532c379218ab765e19213411a51ad57affb0fe61
[scons.git] / test / GetBuildFailures / option-k.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 """
26 Verify that a failed build action with -j works as expected.
27 """
28
29 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
30
31 import TestSCons
32
33 _python_ = TestSCons._python_
34
35 try:
36     import threading
37 except ImportError:
38     # if threads are not supported, then
39     # there is nothing to test
40     TestCmd.no_result()
41     sys.exit()
42
43
44 test = TestSCons.TestSCons()
45
46 contents = r"""\
47 import sys
48 if sys.argv[0] == 'mypass.py':
49     open(sys.argv[3], 'wb').write(open(sys.argv[4], 'rb').read())
50     exit_value = 0
51 elif sys.argv[0] == 'myfail.py':
52     exit_value = 1
53 sys.exit(exit_value)
54 """
55
56 test.write('mypass.py', contents)
57 test.write('myfail.py', contents)
58
59 test.write('SConstruct', """\
60 Command('f3', 'f3.in', r'@%(_python_)s mypass.py -  f3 $TARGET $SOURCE')
61 Command('f4', 'f4.in', r'@%(_python_)s myfail.py f3 f4 $TARGET $SOURCE')
62 Command('f5', 'f5.in', r'@%(_python_)s myfail.py f4 f5 $TARGET $SOURCE')
63 Command('f6', 'f6.in', r'@%(_python_)s mypass.py f5 -  $TARGET $SOURCE')
64
65 def print_build_failures():
66     from SCons.Script import GetBuildFailures
67     bf_list = GetBuildFailures()
68     bf_list.sort(lambda a,b: cmp(a.filename, b.filename))
69     for bf in bf_list:
70         print "%%s failed:  %%s" %% (bf.node, bf.errstr)
71
72 try:
73     import atexit
74 except ImportError:
75     import sys
76     sys.exitfunc = print_build_failures
77 else:
78     atexit.register(print_build_failures)
79 """ % locals())
80
81 test.write('f3.in', "f3.in\n")
82 test.write('f4.in', "f4.in\n")
83 test.write('f5.in', "f5.in\n")
84 test.write('f6.in', "f6.in\n")
85
86 expect_stdout = """\
87 scons: Reading SConscript files ...
88 scons: done reading SConscript files.
89 scons: Building targets ...
90 scons: done building targets (errors occurred during build).
91 f4 failed:  Error 1
92 f5 failed:  Error 1
93 """ % locals()
94
95 expect_stderr = """\
96 scons: *** [f4] Error 1
97 scons: *** [f5] Error 1
98 """
99
100 test.run(arguments = '-k .',
101          status = 2,
102          stdout = expect_stdout,
103          stderr = expect_stderr)
104
105 test.must_match(test.workpath('f3'), 'f3.in\n')
106 test.must_not_exist(test.workpath('f4'))
107 test.must_not_exist(test.workpath('f5'))
108 test.must_match(test.workpath('f6'), 'f6.in\n') 
109
110
111
112 test.pass_test()
113
114 # Local Variables:
115 # tab-width:4
116 # indent-tabs-mode:nil
117 # End:
118 # vim: set expandtab tabstop=4 shiftwidth=4: