Merge pull request #4655 from bdbaddog/fix_new_ninja_package
[scons.git] / test / GetBuildFailures / option-k.py
blob50ad3029809ae8d2ae73bafac5634f4c6951c212
1 #!/usr/bin/env python
3 # MIT License
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.
26 """
27 Verify that a failed build action with -k works as expected.
28 """
30 import TestSCons
32 _python_ = TestSCons._python_
34 try:
35 import threading
36 except ImportError:
37 # if threads are not supported, then
38 # there is nothing to test
39 TestCmd.no_result()
40 sys.exit()
43 test = TestSCons.TestSCons()
45 contents = r"""\
46 import sys
47 if 'mypass.py' in sys.argv[0]:
48 with open(sys.argv[3], 'wb') as ofp, open(sys.argv[4], 'rb') as ifp:
49 ofp.write(ifp.read())
50 exit_value = 0
51 elif 'myfail.py' in sys.argv[0]:
52 exit_value = 1
53 sys.exit(exit_value)
54 """
56 test.write('mypass.py', contents)
57 test.write('myfail.py', contents)
59 test.write('SConstruct', """\
60 DefaultEnvironment(tools=[])
61 Command('f3', 'f3.in', r'@%(_python_)s mypass.py - f3 $TARGET $SOURCE')
62 Command('f4', 'f4.in', r'@%(_python_)s myfail.py f3 f4 $TARGET $SOURCE')
63 Command('f5', 'f5.in', r'@%(_python_)s myfail.py f4 f5 $TARGET $SOURCE')
64 Command('f6', 'f6.in', r'@%(_python_)s mypass.py f5 - $TARGET $SOURCE')
66 def print_build_failures():
67 from SCons.Script import GetBuildFailures
68 for bf in sorted(GetBuildFailures(), key=lambda a: a.filename or 'None'):
69 print("%%s failed: %%s" %% (bf.node, bf.errstr))
71 import atexit
72 atexit.register(print_build_failures)
73 """ % locals())
75 test.write('f3.in', "f3.in\n")
76 test.write('f4.in', "f4.in\n")
77 test.write('f5.in', "f5.in\n")
78 test.write('f6.in', "f6.in\n")
80 expect_stdout = """\
81 scons: Reading SConscript files ...
82 scons: done reading SConscript files.
83 scons: Building targets ...
84 scons: done building targets (errors occurred during build).
85 f4 failed: Error 1
86 f5 failed: Error 1
87 """
89 expect_stderr = """\
90 scons: *** [f4] Error 1
91 scons: *** [f5] Error 1
92 """
94 test.run(arguments = '-k .', status = 2, stdout=None, stderr=None)
95 test.must_contain_exactly_lines(test.stdout(), expect_stdout, title='stdout')
96 test.must_contain_exactly_lines(test.stderr(), expect_stderr, title='stderr')
98 test.must_match(test.workpath('f3'), 'f3.in\n')
99 test.must_not_exist(test.workpath('f4'))
100 test.must_not_exist(test.workpath('f5'))
101 test.must_match(test.workpath('f6'), 'f6.in\n')
104 test.pass_test()
106 # Local Variables:
107 # tab-width:4
108 # indent-tabs-mode:nil
109 # End:
110 # vim: set expandtab tabstop=4 shiftwidth=4: