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(match
= TestSCons
.match_re_dotall
)
35 SConstruct_path
= test
.workpath('SConstruct')
37 test
.write(SConstruct_path
, """\
38 def func(source = None, target = None, env = None):
39 raise Exception("func exception")
40 B = Builder(action = func)
41 env = Environment(BUILDERS = { 'B' : B })
42 env.B(target = 'foo.out', source = 'foo.in')
45 test
.write('foo.in', "foo.in\n")
47 expected_stderr
= r
"""scons: \*\*\* \[foo.out\] Exception : func exception
48 Traceback \((most recent call|innermost) last\):
49 ( File ".+", line \d+, in \S+
51 )*( File ".+", line \d+, in \S+
52 )*( File ".+", line \d+, in \S+
54 )* File "%s", line 2, in func
55 raise Exception\("func exception"\)
56 Exception: func exception
57 """ % re
.escape(SConstruct_path
)
59 test
.run(arguments
= "foo.out", stderr
= expected_stderr
, status
= 2)
61 test
.run(arguments
= "-j2 foo.out", stderr
= expected_stderr
, status
= 2)
64 # Verify that exceptions caused by exit values of builder actions are
65 # correctly signalled, for both Serial and Parallel jobs.
67 test
.write('myfail.py', r
"""\
72 test
.write(SConstruct_path
, """
73 Fail = Builder(action = r'%(_python_)s myfail.py $TARGETS $SOURCE')
74 env = Environment(BUILDERS = { 'Fail' : Fail })
75 env.Fail(target = 'out.f1', source = 'in.f1')
78 test
.write('in.f1', "in.f1\n")
80 expected_stderr
= "scons: \\*\\*\\* \\[out.f1\\] Error 1\n"
82 test
.run(arguments
= '.', status
= 2, stderr
= expected_stderr
)
83 test
.run(arguments
= '-j2 .', status
= 2, stderr
= expected_stderr
)
86 # Verify that all exceptions from simultaneous tasks are reported,
87 # even if the exception is raised during the Task.prepare()
90 test
.write(SConstruct_path
, """
91 Fail = Builder(action = r'%(_python_)s myfail.py $TARGETS $SOURCE')
92 env = Environment(BUILDERS = { 'Fail' : Fail })
93 env.Fail(target = 'out.f1', source = 'in.f1')
94 env.Fail(target = 'out.f2', source = 'in.f2')
95 env.Fail(target = 'out.f3', source = 'in.f3')
98 # in.f2 is not created to cause a Task.prepare exception
99 test
.write('in.f1', 'in.f1\n')
100 test
.write('in.f3', 'in.f3\n')
102 # In Serial task mode, get the first exception and stop
103 test
.run(arguments
= '.', status
= 2, stderr
= expected_stderr
)
105 # In Parallel task mode, we will get all three exceptions.
107 expected_stderr_list
= [
108 "scons: *** [out.f1] Error 1\n",
109 "scons: *** [out.f2] Source `in.f2' not found, needed by target `out.f2'.\n",
110 "scons: *** [out.f3] Error 1\n",
113 # To get all three exceptions simultaneously, we execute -j7 to create
114 # one thread each for the SConstruct file and {in,out}.f[123]. Note that
115 # it's important that the input (source) files sort earlier alphabetically
116 # than the output files, so they're visited first in the dependency graph
117 # walk of '.' and are already considered up-to-date when we kick off the
118 # "simultaneous" builds of the output (target) files.
120 test
.run(arguments
= '-j7 -k .', status
= 2, stderr
= None)
122 test
.must_contain_all_lines(test
.stderr(), expected_stderr_list
)
129 # indent-tabs-mode:nil
131 # vim: set expandtab tabstop=4 shiftwidth=4: