5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 _python_
= TestSCons
._python
_
32 test
= TestSCons
.TestSCons()
34 test
.subdir('one', 'two', 'three')
36 test
.write('build.py', r
"""
38 exitval = int(sys.argv[1])
40 with open(sys.argv[2], 'w') as f, open(sys.argv[3], 'r') as infp:
45 test
.write(['one', 'SConstruct'], """
46 B0 = Builder(action = r'%(_python_)s ../build.py 0 $TARGET $SOURCES')
47 B1 = Builder(action = r'%(_python_)s ../build.py 1 $TARGET $SOURCES')
48 DefaultEnvironment(tools=[]) # test speedup
49 env = Environment(BUILDERS = { 'B0' : B0, 'B1' : B1 })
50 env.B1(target = 'f1.out', source = 'f1.in')
51 env.B0(target = 'f2.out', source = 'f2.in')
52 env.B0(target = 'f3.out', source = 'f3.in')
55 test
.write(['one', 'f1.in'], "one/f1.in\n")
56 test
.write(['one', 'f2.in'], "one/f2.in\n")
57 test
.write(['one', 'f3.in'], "one/f3.in\n")
59 test
.run(chdir
= 'one', arguments
= "f1.out f2.out f3.out",
60 stderr
= "scons: *** [f1.out] Error 1\n", status
= 2)
62 test
.fail_test(os
.path
.exists(test
.workpath('f1.out')))
63 test
.fail_test(os
.path
.exists(test
.workpath('f2.out')))
64 test
.fail_test(os
.path
.exists(test
.workpath('f3.out')))
66 test
.write(['two', 'SConstruct'], """
67 B0 = Builder(action = r'%(_python_)s ../build.py 0 $TARGET $SOURCES')
68 B1 = Builder(action = r'%(_python_)s ../build.py 1 $TARGET $SOURCES')
69 DefaultEnvironment(tools=[]) # test speedup
70 env = Environment(BUILDERS = { 'B0': B0, 'B1' : B1 })
71 env.B0(target = 'f1.out', source = 'f1.in')
72 env.B1(target = 'f2.out', source = 'f2.in')
73 env.B0(target = 'f3.out', source = 'f3.in')
76 test
.write(['two', 'f1.in'], "two/f1.in\n")
77 test
.write(['two', 'f2.in'], "two/f2.in\n")
78 test
.write(['two', 'f3.in'], "two/f3.in\n")
80 test
.run(chdir
= 'two', arguments
= "f1.out f2.out f3.out",
81 stderr
= "scons: *** [f2.out] Error 1\n", status
= 2)
83 test
.must_match(['two', 'f1.out'], "two/f1.in\n", mode
='r')
84 test
.fail_test(os
.path
.exists(test
.workpath('f2.out')))
85 test
.fail_test(os
.path
.exists(test
.workpath('f3.out')))
87 test
.write(['three', 'SConstruct'], """
88 B0 = Builder(action = r'%(_python_)s ../build.py 0 $TARGET $SOURCES')
89 B1 = Builder(action = r'%(_python_)s ../build.py 1 $TARGET $SOURCES')
90 DefaultEnvironment(tools=[]) # test speedup
91 env = Environment(BUILDERS = { 'B0' : B0, 'B1': B1 })
92 env.B0(target = 'f1.out', source = 'f1.in')
93 env.B0(target = 'f2.out', source = 'f2.in')
94 env.B1(target = 'f3.out', source = 'f3.in')
97 test
.write(['three', 'f1.in'], "three/f1.in\n")
98 test
.write(['three', 'f2.in'], "three/f2.in\n")
99 test
.write(['three', 'f3.in'], "three/f3.in\n")
101 test
.run(chdir
= 'three', arguments
= "f1.out f2.out f3.out",
102 stderr
= "scons: *** [f3.out] Error 1\n", status
= 2)
104 test
.must_match(['three', 'f1.out'], "three/f1.in\n", mode
='r')
105 test
.must_match(['three', 'f2.out'], "three/f2.in\n", mode
='r')
106 test
.fail_test(os
.path
.exists(test
.workpath('f3.out')))
108 test
.write('SConstruct', """
109 DefaultEnvironment(tools=[]) # test speedup
111 env['ENV']['PATH'] = ''
112 env.Command(target='foo.out', source=[], action='not_a_program')
115 test
.run(status
=2, stderr
=None)
116 test
.must_not_contain_any_line(test
.stderr(), ['Exception', 'Traceback'])
119 # Test ETOOLONG (arg list too long). This is not in exitvalmap,
120 # but that shouldn't cause a scons traceback.
121 long_cmd
= 'xyz ' + "foobarxyz" * 100000
122 test
.write('SConstruct', """
123 DefaultEnvironment(tools=[]) # test speedup
125 env.Command(target='longcmd.out', source=[], action='echo %s')
128 test
.run(status
=2, stderr
=None)
130 test
.must_not_contain_any_line(test
.stderr(), ['Exception', 'Traceback'])
132 #TODO: This was originally commented out because of a problem with 1.5.2,
133 # but it doesn't work on later Pythons, either.
135 # "too long", # posix
136 # "nvalid argument", # win32
138 #test.must_contain_any_line(test.stderr(), expected)
141 # Test bad shell ('./one' is a dir, so it can't be used as a shell).
142 # This will also give an exit status not in exitvalmap,
143 # with error "Permission denied" or "No such file or directory".
144 test
.write('SConstruct', """
145 DefaultEnvironment(tools=[]) # test speedup
148 env.Command(target='badshell.out', source=[], action='foo')
151 test
.run(status
=2, stderr
=None)
152 test
.must_not_contain_any_line(test
.stderr(), ['Exception', 'Traceback'])
158 test
.must_contain_any_line(test
.stderr(), expect
)
161 # Test command with exit status -1.
162 # Should not give traceback.
163 test
.write('SConstruct', """
165 DefaultEnvironment(tools=[]) # test speedup
166 env = Environment(ENV = os.environ)
167 env.Command('dummy.txt', None, ['python -c "import sys; sys.exit(-1)"'])
170 test
.run(status
=2, stderr
=None)
171 test
.must_not_contain_any_line(test
.stderr(), ['Exception', 'Traceback'])
174 # Test SConscript with errors and an atexit function.
175 # Should not give traceback; the task error should get converted
177 test
.write('SConstruct', """
180 DefaultEnvironment(tools=[]) # test speedup
184 env.Install("target", "dir1/myFile")
185 env2.Install("target", "dir2/myFile")
187 def print_build_failures():
188 from SCons.Script import GetBuildFailures
189 for bf in GetBuildFailures():
192 atexit.register(print_build_failures)
195 test
.run(status
=2, stderr
=None)
196 test
.must_not_contain_any_line(test
.stderr(), ['Exception', 'Traceback'])
199 # Bug #1053: Alias is called "all", but default is the File "all"
200 test
.write('SConstruct', """
201 DefaultEnvironment(tools=[]) # test speedup
204 env.Alias("all", env.Install("dir", "file.txt"))
206 test
.run(status
=2, match
=TestSCons
.match_re
, stderr
=\
207 r
"""scons: \*\*\* Do not know how to make File target `all' \(.*all\). Stop.
210 # No tests failed; OK.
215 # indent-tabs-mode:nil
217 # vim: set expandtab tabstop=4 shiftwidth=4: