Added fix for TeX includes with same name as subdirs.
[scons.git] / test / builderrors.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 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import os
28
29 import TestSCons
30
31 _python_ = TestSCons._python_
32
33 test = TestSCons.TestSCons()
34
35 test.subdir('one', 'two', 'three')
36
37 test.write('build.py', r"""
38 import sys
39 exitval = int(sys.argv[1])
40 if exitval == 0:
41     contents = open(sys.argv[3], 'rb').read()
42     file = open(sys.argv[2], 'wb')
43     file.write(contents)
44     file.close()
45 sys.exit(exitval)
46 """)
47
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')
55 """ % locals())
56
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")
60
61 test.run(chdir = 'one', arguments = "f1.out f2.out f3.out",
62          stderr = "scons: *** [f1.out] Error 1\n", status = 2)
63
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')))
67
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')
75 """ % locals())
76
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")
80
81 test.run(chdir = 'two', arguments = "f1.out f2.out f3.out",
82          stderr = "scons: *** [f2.out] Error 1\n", status = 2)
83
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')))
87
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')
95 """ % locals())
96
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")
100
101 test.run(chdir = 'three', arguments = "f1.out f2.out f3.out",
102          stderr = "scons: *** [f3.out] Error 1\n", status = 2)
103
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')))
107
108 test.write('SConstruct', """
109 env=Environment()
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')
115 """)
116
117 test.run(status=2, stderr=None)
118 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
119
120
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', """
125 env=Environment()
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')
130 """%long_cmd)
131
132 test.run(status=2, stderr=None)
133
134 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
135
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.
139 #expected = [
140 #    "too long", # posix
141 #    "nvalid argument", # win32
142 #]
143 #test.must_contain_any_line(test.stderr(), expected)
144
145
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', """
150 env=Environment()
151 if env['PLATFORM'] in ('posix', 'darwin'):
152     from SCons.Platform.posix import fork_spawn
153     env['SPAWN'] = fork_spawn
154 env['SHELL'] = 'one'
155 env.Command(target='badshell.out', source=[], action='foo')
156 """)
157
158 test.run(status=2, stderr=None)
159 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
160 expect = [
161     'No such file',
162     'Permission denied',
163     'permission denied',
164 ]
165 test.must_contain_any_line(test.stderr(), expect)
166
167
168 # Test command with exit status -1.
169 # Should not give traceback.
170 test.write('SConstruct', """
171 import os
172 env = Environment(ENV = os.environ)
173 env.Command('dummy.txt', None, ['python -c "import sys; sys.exit(-1)"'])
174 """)
175
176 test.run(status=2, stderr=None)
177 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
178
179
180 # Test SConscript with errors and an atexit function.
181 # Should not give traceback; the task error should get converted
182 # to a BuildError.
183 test.write('SConstruct', """
184 import atexit
185
186 env = Environment()
187 env2 = env.Clone()
188
189 env.Install("target", "dir1/myFile")
190 env2.Install("target", "dir2/myFile")
191
192 def print_build_failures():
193     from SCons.Script import GetBuildFailures
194     for bf in GetBuildFailures():
195         print bf.action
196
197 atexit.register(print_build_failures)
198 """)
199
200 test.run(status=2, stderr=None)
201 test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
202
203
204 # Bug #1053: Alias is called "all", but default is the File "all"
205 test.write('SConstruct', """
206 env = Environment()
207 env.Default("all")
208 env.Alias("all", env.Install("dir", "file.txt"))
209 """)
210 test.run(status=2, match=TestSCons.match_re, stderr="""\
211 scons: \*\*\* Do not know how to make File target `all' \(.*all\).  Stop.
212 """)
213
214 # No tests failed; OK.
215 test.pass_test()
216
217 # Local Variables:
218 # tab-width:4
219 # indent-tabs-mode:nil
220 # End:
221 # vim: set expandtab tabstop=4 shiftwidth=4: