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 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
31 _python_ = TestSCons._python_
33 test = TestSCons.TestSCons()
35 test.subdir('one', 'two', 'three')
37 test.write('build.py', r"""
39 exitval = int(sys.argv[1])
41 contents = open(sys.argv[3], 'rb').read()
42 file = open(sys.argv[2], 'wb')
48 test.write(['one', 'SConstruct'], """
49 B0 = Builder(action = r'%(_python_)s ../build.py 0 $TARGET $SOURCES')
50 B1 = Builder(action = r'%(_python_)s ../build.py 1 $TARGET $SOURCES')
51 env = Environment(BUILDERS = { 'B0' : B0, 'B1' : B1 })
52 env.B1(target = 'f1.out', source = 'f1.in')
53 env.B0(target = 'f2.out', source = 'f2.in')
54 env.B0(target = 'f3.out', source = 'f3.in')
57 test.write(['one', 'f1.in'], "one/f1.in\n")
58 test.write(['one', 'f2.in'], "one/f2.in\n")
59 test.write(['one', 'f3.in'], "one/f3.in\n")
61 test.run(chdir = 'one', arguments = "f1.out f2.out f3.out",
62 stderr = "scons: *** [f1.out] Error 1\n", status = 2)
64 test.fail_test(os.path.exists(test.workpath('f1.out')))
65 test.fail_test(os.path.exists(test.workpath('f2.out')))
66 test.fail_test(os.path.exists(test.workpath('f3.out')))
68 test.write(['two', 'SConstruct'], """
69 B0 = Builder(action = r'%(_python_)s ../build.py 0 $TARGET $SOURCES')
70 B1 = Builder(action = r'%(_python_)s ../build.py 1 $TARGET $SOURCES')
71 env = Environment(BUILDERS = { 'B0': B0, 'B1' : B1 })
72 env.B0(target = 'f1.out', source = 'f1.in')
73 env.B1(target = 'f2.out', source = 'f2.in')
74 env.B0(target = 'f3.out', source = 'f3.in')
77 test.write(['two', 'f1.in'], "two/f1.in\n")
78 test.write(['two', 'f2.in'], "two/f2.in\n")
79 test.write(['two', 'f3.in'], "two/f3.in\n")
81 test.run(chdir = 'two', arguments = "f1.out f2.out f3.out",
82 stderr = "scons: *** [f2.out] Error 1\n", status = 2)
84 test.fail_test(test.read(['two', 'f1.out']) != "two/f1.in\n")
85 test.fail_test(os.path.exists(test.workpath('f2.out')))
86 test.fail_test(os.path.exists(test.workpath('f3.out')))
88 test.write(['three', 'SConstruct'], """
89 B0 = Builder(action = r'%(_python_)s ../build.py 0 $TARGET $SOURCES')
90 B1 = Builder(action = r'%(_python_)s ../build.py 1 $TARGET $SOURCES')
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.fail_test(test.read(['three', 'f1.out']) != "three/f1.in\n")
105 test.fail_test(test.read(['three', 'f2.out']) != "three/f2.in\n")
106 test.fail_test(os.path.exists(test.workpath('f3.out')))
108 test.write('SConstruct', """
110 if env['PLATFORM'] == 'posix':
111 from SCons.Platform.posix import fork_spawn
112 env['SPAWN'] = fork_spawn
113 env['ENV']['PATH'] = ''
114 env.Command(target='foo.out', source=[], action='not_a_program')
117 test.run(status=2, stderr=None)
118 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
121 # Test ETOOLONG (arg list too long). This is not in exitvalmap,
122 # but that shouldn't cause a scons traceback.
123 long_cmd = 'xyz ' + "foobarxyz" * 100000
124 test.write('SConstruct', """
126 if env['PLATFORM'] == 'posix':
127 from SCons.Platform.posix import fork_spawn
128 env['SPAWN'] = fork_spawn
129 env.Command(target='longcmd.out', source=[], action='echo %s')
132 test.run(status=2, stderr=None)
134 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
136 # Python 1.5.2 on a FC3 system doesn't even get to the exitvalmap
137 # because it fails with "No such file or directory." Just comment
138 # this out for now, there are plenty of other good tests below.
140 # "too long", # posix
141 # "nvalid argument", # win32
143 #test.must_contain_any_line(test.stderr(), expected)
146 # Test bad shell ('./one' is a dir, so it can't be used as a shell).
147 # This will also give an exit status not in exitvalmap,
148 # with error "Permission denied" or "No such file or directory".
149 test.write('SConstruct', """
151 if env['PLATFORM'] in ('posix', 'darwin'):
152 from SCons.Platform.posix import fork_spawn
153 env['SPAWN'] = fork_spawn
155 env.Command(target='badshell.out', source=[], action='foo')
158 test.run(status=2, stderr=None)
159 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
165 test.must_contain_any_line(test.stderr(), expect)
168 # Test command with exit status -1.
169 # Should not give traceback.
170 test.write('SConstruct', """
172 env = Environment(ENV = os.environ)
173 env.Command('dummy.txt', None, ['python -c "import sys; sys.exit(-1)"'])
176 test.run(status=2, stderr=None)
177 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
180 # Test SConscript with errors and an atexit function.
181 # Should not give traceback; the task error should get converted
183 test.write('SConstruct', """
189 env.Install("target", "dir1/myFile")
190 env2.Install("target", "dir2/myFile")
192 def print_build_failures():
193 from SCons.Script import GetBuildFailures
194 for bf in GetBuildFailures():
197 atexit.register(print_build_failures)
200 test.run(status=2, stderr=None)
201 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
204 # Bug #1053: Alias is called "all", but default is the File "all"
205 test.write('SConstruct', """
208 env.Alias("all", env.Install("dir", "file.txt"))
210 test.run(status=2, match=TestSCons.match_re, stderr="""\
211 scons: \*\*\* Do not know how to make File target `all' \(.*all\). Stop.
214 # No tests failed; OK.
219 # indent-tabs-mode:nil
221 # vim: set expandtab tabstop=4 shiftwidth=4: