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.
26 Verify that the GetBuildFailures() function returns a list of
27 BuildError exceptions. Also verify printing the BuildError
28 attributes we expect to be most commonly used.
31 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
36 _python_ = TestSCons._python_
41 # if threads are not supported, then
42 # there is nothing to test
47 test = TestSCons.TestSCons()
51 if sys.argv[0] == 'mypass.py':
52 open(sys.argv[3], 'wb').write(open(sys.argv[4], 'rb').read())
54 elif sys.argv[0] == 'myfail.py':
59 test.write('mypass.py', contents)
60 test.write('myfail.py', contents)
62 test.write('SConstruct', """\
63 Command('f03', 'f03.in', r'@%(_python_)s mypass.py - f03 $TARGET $SOURCE')
64 Command('f04', 'f04.in', r'@%(_python_)s myfail.py f03 f04 $TARGET $SOURCE')
65 Command('f05', 'f05.in', r'@%(_python_)s myfail.py f04 f05 $TARGET $SOURCE')
66 Command('f06', 'f06.in', r'@%(_python_)s mypass.py f05 - $TARGET $SOURCE')
67 Command('f07', 'f07.in', r'@%(_python_)s mypass.py f07 - $TARGET $SOURCE')
70 def raiseExcAction(exc):
71 def action(env, target, source, exc=exc):
74 def returnExcAction(exc):
75 def action(env, target, source, exc=exc):
78 class MyBuildError(SCons.Errors.BuildError):
81 Command('f08', 'f08.in', raiseExcAction(SCons.Errors.UserError("My User Error")))
82 Command('f09', 'f09.in', returnExcAction(SCons.Errors.UserError("My User Error")))
83 Command('f10', 'f10.in', raiseExcAction(MyBuildError(errstr="My Build Error", status=7)))
84 Command('f11', 'f11.in', returnExcAction(MyBuildError(errstr="My Build Error", status=7)))
85 Command('f12', 'f12.in', raiseExcAction(EnvironmentError(123, "My EnvironmentError", "f12")))
86 Command('f13', 'f13.in', returnExcAction(EnvironmentError(123, "My EnvironmentError", "f13")))
87 Command('f14', 'f14.in', raiseExcAction(SCons.Errors.InternalError("My InternalError")))
88 Command('f15', 'f15.in', returnExcAction(SCons.Errors.InternalError("My InternalError")))
90 def print_build_failures():
91 from SCons.Script import GetBuildFailures
92 for bf in sorted(GetBuildFailures(), key=lambda t: str(t.node)):
93 assert( isinstance(bf, SCons.Errors.BuildError) )
94 print "BF: %%s failed (%%s): %%s" %% (bf.node, bf.status, bf.errstr)
96 print "BF: %%s" %% " ".join(Flatten(bf.command))
102 sys.exitfunc = print_build_failures
104 atexit.register(print_build_failures)
107 test.write('f03.in', "f03.in\n")
108 test.write('f04.in', "f04.in\n")
109 test.write('f05.in', "f05.in\n")
110 test.write('f06.in', "f06.in\n")
111 # f07.in is intentionally missing...
112 test.write('f08.in', "f08.in\n")
113 test.write('f09.in', "f09.in\n")
114 test.write('f10.in', "f10.in\n")
115 test.write('f11.in', "f11.in\n")
116 test.write('f12.in', "f12.in\n")
117 test.write('f13.in', "f13.in\n")
118 test.write('f14.in', "f14.in\n")
119 test.write('f15.in', "f15.in\n")
122 scons: Reading SConscript files ...
123 scons: done reading SConscript files.
124 scons: Building targets ...
125 scons: building terminated because of errors.
126 BF: f04 failed (1): Error 1
127 BF: %(_python_)s myfail.py f03 f04 "f04" "f04.in"
131 scons: *** [f04] Error 1
134 test.run(arguments = '.',
136 stdout = expect_stdout,
137 stderr = expect_stderr)
139 test.must_match(test.workpath('f03'), 'f03.in\n')
140 test.must_not_exist(test.workpath('f04'))
141 test.must_not_exist(test.workpath('f05'))
142 test.must_not_exist(test.workpath('f06'))
143 test.must_not_exist(test.workpath('f07'))
144 test.must_not_exist(test.workpath('f08'))
145 test.must_not_exist(test.workpath('f09'))
146 test.must_not_exist(test.workpath('f10'))
147 test.must_not_exist(test.workpath('f11'))
148 test.must_not_exist(test.workpath('f12'))
149 test.must_not_exist(test.workpath('f13'))
150 test.must_not_exist(test.workpath('f14'))
151 test.must_not_exist(test.workpath('f15'))
154 expect_stdout = re.escape("""\
155 scons: Reading SConscript files ...
156 scons: done reading SConscript files.
157 scons: Building targets ...
158 action(["f08"], ["f08.in"])
159 action(["f09"], ["f09.in"])
160 action(["f10"], ["f10.in"])
161 action(["f11"], ["f11.in"])
162 action(["f12"], ["f12.in"])
163 action(["f13"], ["f13.in"])
164 action(["f14"], ["f14.in"])
165 action(["f15"], ["f15.in"])
166 scons: done building targets (errors occurred during build).
167 BF: f04 failed (1): Error 1
168 BF: %(_python_)s myfail.py f03 f04 "f04" "f04.in"
169 BF: f05 failed (1): Error 1
170 BF: %(_python_)s myfail.py f04 f05 "f05" "f05.in"
171 BF: f07 failed (2): Source `f07.in' not found, needed by target `f07'.
172 BF: f08 failed (2): My User Error
173 BF: action(["f08"], ["f08.in"])
174 BF: f09 failed (2): My User Error
175 BF: action(["f09"], ["f09.in"])
176 BF: f10 failed (7): My Build Error
177 BF: action(["f10"], ["f10.in"])
178 BF: f11 failed (7): My Build Error
179 BF: action(["f11"], ["f11.in"])
180 BF: f12 failed (123): My EnvironmentError
181 BF: action(["f12"], ["f12.in"])
182 BF: f13 failed (123): My EnvironmentError
183 BF: action(["f13"], ["f13.in"])
184 BF: f14 failed (2): InternalError : My InternalError
185 BF: action(["f14"], ["f14.in"])
186 BF: f15 failed (2): InternalError : My InternalError
187 BF: action(["f15"], ["f15.in"])
190 expect_stderr = re.escape("""\
191 scons: *** [f04] Error 1
192 scons: *** [f05] Error 1
193 scons: *** [f07] Source `f07.in' not found, needed by target `f07'.
194 scons: *** [f08] My User Error
195 scons: *** [f09] My User Error
196 scons: *** [f10] My Build Error
197 scons: *** [f11] My Build Error
198 scons: *** [f12] f12: My EnvironmentError
199 scons: *** [f13] f13: My EnvironmentError
200 scons: *** [f14] InternalError : My InternalError
203 Traceback \((most recent call|innermost) last\):
204 ( File ".+", line \d+, in \S+
206 )*( File ".+", line \d+, in \S+
207 )*( File ".+", line \d+, in \S+
212 scons: *** [f15] InternalError : My InternalError
215 test.run(arguments = '-k .',
217 stdout = expect_stdout,
218 stderr = expect_stderr,
219 match = TestSCons.match_re_dotall)
221 test.must_match(test.workpath('f03'), 'f03.in\n')
222 test.must_not_exist(test.workpath('f04'))
223 test.must_not_exist(test.workpath('f05'))
224 test.must_match(test.workpath('f06'), 'f06.in\n')
225 test.must_not_exist(test.workpath('f07'))
226 test.must_not_exist(test.workpath('f08'))
227 test.must_not_exist(test.workpath('f09'))
228 test.must_not_exist(test.workpath('f10'))
229 test.must_not_exist(test.workpath('f11'))
230 test.must_not_exist(test.workpath('f12'))
231 test.must_not_exist(test.workpath('f13'))
232 test.must_not_exist(test.workpath('f14'))
233 test.must_not_exist(test.workpath('f15'))
240 # indent-tabs-mode:nil
242 # vim: set expandtab tabstop=4 shiftwidth=4: