Added fix for TeX includes with same name as subdirs.
[scons.git] / test / option--duplicate.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 """
26 This tests the --duplicate command line option, and the duplicate
27 SConscript settable option.
28 """
29
30 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
31
32 import os
33 import stat
34 import TestSCons
35
36 python = TestSCons.python
37
38 test = TestSCons.TestSCons()
39
40 test.write('SConstruct', """
41 try:
42     duplicate = ARGUMENTS['duplicate']
43     SetOption('duplicate', duplicate)
44 except KeyError:
45     pass
46 VariantDir('build', '.', duplicate=1)
47 SConscript('build/SConscript')
48 """)
49
50 test.write('SConscript', '')
51
52 hard = hasattr(os,'link')
53 soft = hasattr(os,'symlink')
54 copy = 1 # should always work
55
56 bss = test.workpath('build/SConscript')
57
58 criterion_hardlinks = {
59     'hard'      : lambda nl, islink: nl == 2 and not islink,
60     'soft'      : lambda nl, islink: nl == 1 and islink,
61     'copy'      : lambda nl, islink: nl == 1 and not islink,
62 }
63
64 criterion_no_hardlinks = {
65     'hard'      : lambda nl, islink: not islink,
66     'soft'      : lambda nl, islink: islink,
67     'copy'      : lambda nl, islink: not islink,
68 }
69
70 # On systems without hard linking, it doesn't make sense to check ST_NLINK
71 if hard:
72     criterion = criterion_hardlinks
73 else:
74     criterion = criterion_no_hardlinks
75
76 description = {
77     'hard'      : 'a hard link',
78     'soft'      : 'a soft link',
79     'copy'      : 'copied',
80 }
81
82 def testLink(file, type):
83     nl = os.stat(file)[stat.ST_NLINK]
84     islink = os.path.islink(file)
85     assert criterion[type](nl, islink), \
86            "Expected %s to be %s (nl %d, islink %d)" \
87            % (file, description[type], nl, islink)
88
89 def RunTest(order, type, bss):
90     # Test the command-line --duplicate option.
91     test.run(arguments='--duplicate='+order)
92     testLink(bss, type)
93
94     # Test setting the option in the SConstruct file.
95     test.run(arguments='duplicate='+order)
96     testLink(bss, type)
97
98     # Clean up for next run.
99     os.unlink(bss)
100
101 # test the default (hard-soft-copy)
102 if hard:   type='hard'
103 elif soft: type='soft'
104 else:      type='copy'
105 RunTest('hard-soft-copy', type, bss)
106
107 if soft:   type='soft'
108 elif hard: type='hard'
109 else:      type='copy'
110 RunTest('soft-hard-copy', type, bss)
111
112 if soft:   type='soft'
113 else:      type='copy'
114 RunTest('soft-copy', type, bss)
115
116 if hard:   type='hard'
117 else:      type='copy'
118 RunTest('hard-copy', type, bss)
119
120 type='copy'
121 RunTest('copy', type, bss)
122
123 test.run(arguments='--duplicate=nonsense', status=2, stderr="""\
124 usage: scons [OPTION] [TARGET] ...
125
126 SCons error: `nonsense' is not a valid duplication style.
127 """)
128
129 test.pass_test()
130
131 # Local Variables:
132 # tab-width:4
133 # indent-tabs-mode:nil
134 # End:
135 # vim: set expandtab tabstop=4 shiftwidth=4: