Issue 1568: fix a stack trace when --debug=include tries to handle
[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 string
33 import sys
34 import os
35 import os.path
36 import stat
37 import TestSCons
38
39 python = TestSCons.python
40
41 test = TestSCons.TestSCons()
42
43 test.write('SConstruct', """
44 try:
45     duplicate = ARGUMENTS['duplicate']
46     SetOption('duplicate', duplicate)
47 except KeyError:
48     pass
49 VariantDir('build', '.', duplicate=1)
50 SConscript('build/SConscript')
51 """)
52
53 test.write('SConscript', '')
54
55 hard = hasattr(os,'link')
56 soft = hasattr(os,'symlink')
57 copy = 1 # should always work
58
59 bss = test.workpath('build/SConscript')
60
61 criterion = {
62     'hard'      : lambda nl, islink: nl == 2 and not islink,
63     'soft'      : lambda nl, islink: nl == 1 and islink,
64     'copy'      : lambda nl, islink: nl == 1 and not islink,
65 }
66
67 description = {
68     'hard'      : 'a hard link',
69     'soft'      : 'a soft link',
70     'copy'      : 'copied',
71 }
72
73 def testLink(file, type):
74     nl = os.stat(file)[stat.ST_NLINK]
75     islink = os.path.islink(file)
76     assert criterion[type](nl, islink), \
77            "Expected %s to be %s (nl %d, islink %d)" \
78            % (file, description[type], nl, islink)
79
80 def RunTest(order, type, bss):
81     # Test the command-line --duplicate option.
82     test.run(arguments='--duplicate='+order)
83     testLink(bss, type)
84
85     # Test setting the option in the SConstruct file.
86     test.run(arguments='duplicate='+order)
87     testLink(bss, type)
88
89     # Clean up for next run.
90     os.unlink(bss)
91
92 # test the default (hard-soft-copy)
93 if hard:   type='hard'
94 elif soft: type='soft'
95 else:      type='copy'
96 RunTest('hard-soft-copy', type, bss)
97
98 if soft:   type='soft'
99 elif hard: type='hard'
100 else:      type='copy'
101 RunTest('soft-hard-copy', type, bss)
102
103 if soft:   type='soft'
104 else:      type='copy'
105 RunTest('soft-copy', type, bss)
106
107 if hard:   type='hard'
108 else:      type='copy'
109 RunTest('hard-copy', type, bss)
110
111 type='copy'
112 RunTest('copy', type, bss)
113
114 test.run(arguments='--duplicate=nonsense', status=2, stderr="""\
115 usage: scons [OPTION] [TARGET] ...
116
117 SCons error: `nonsense' is not a valid duplication style.
118 """)
119
120 test.pass_test()