updates for 4.1.0 release
[scons.git] / test / option--duplicate.py
blob91dc61c94a2ceb20a42e3bd199adfd903495e9a6
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 """
26 This tests the --duplicate command line option, and the duplicate
27 SConscript settable option.
28 """
30 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
32 import os
33 import sys
34 import stat
35 import TestSCons
37 python = TestSCons.python
39 test = TestSCons.TestSCons()
41 test.write('SConstruct', """
42 DefaultEnvironment(tools=[])
43 try:
44 duplicate = ARGUMENTS['duplicate']
45 SetOption('duplicate', duplicate)
46 except KeyError:
47 pass
48 VariantDir('build', '.', duplicate=1)
49 SConscript('build/SConscript')
50 """)
52 test.write('SConscript', '')
54 # we don't use links on windows currently as they
55 # require permissions not usually set
56 hard = hasattr(os, 'link') and sys.platform != 'win32'
57 soft = hasattr(os, 'symlink') and sys.platform != 'win32'
58 copy = 1 # should always work
60 bss = test.workpath('build/SConscript')
62 criterion_hardlinks = {
63 'hard' : lambda nl, islink: nl == 2 and not islink,
64 'soft' : lambda nl, islink: nl == 1 and islink,
65 'copy' : lambda nl, islink: nl == 1 and not islink,
68 criterion_no_hardlinks = {
69 'hard' : lambda nl, islink: not islink,
70 'soft' : lambda nl, islink: islink,
71 'copy' : lambda nl, islink: not islink,
74 # On systems without hard linking, it doesn't make sense to check ST_NLINK
75 if hard:
76 criterion = criterion_hardlinks
77 else:
78 criterion = criterion_no_hardlinks
80 description = {
81 'hard' : 'a hard link',
82 'soft' : 'a soft link',
83 'copy' : 'copied',
86 def testLink(file, type):
87 nl = os.stat(file)[stat.ST_NLINK]
88 islink = os.path.islink(file)
89 assert criterion[type](nl, islink), \
90 "Expected %s to be %s (nl %d, islink %d)" \
91 % (file, description[type], nl, islink)
93 def RunTest(order, type, bss):
94 # Test the command-line --duplicate option.
95 test.run(arguments='--duplicate='+order)
96 testLink(bss, type)
98 # Test setting the option in the SConstruct file.
99 test.run(arguments='duplicate='+order)
100 testLink(bss, type)
102 # Clean up for next run.
103 os.unlink(bss)
105 # test the default (hard-soft-copy)
106 if hard: type='hard'
107 elif soft: type='soft'
108 else: type='copy'
109 RunTest('hard-soft-copy', type, bss)
111 if soft: type='soft'
112 elif hard: type='hard'
113 else: type='copy'
114 RunTest('soft-hard-copy', type, bss)
116 if soft: type='soft'
117 else: type='copy'
118 RunTest('soft-copy', type, bss)
120 if hard: type='hard'
121 else: type='copy'
122 RunTest('hard-copy', type, bss)
124 type='copy'
125 RunTest('copy', type, bss)
127 test.run(arguments='--duplicate=nonsense', status=2, stderr="""\
128 usage: scons [OPTION] [TARGET] ...
130 SCons Error: `nonsense' is not a valid duplication option type, try:
131 hard-soft-copy, soft-hard-copy, hard-copy, soft-copy, copy
132 """)
134 test.pass_test()
136 # Local Variables:
137 # tab-width:4
138 # indent-tabs-mode:nil
139 # End:
140 # vim: set expandtab tabstop=4 shiftwidth=4: