updates for 4.1.0 release
[scons.git] / test / option-k.py
blobd6c81ea859f688cc58e0639d69e4c1fcaaf1a283
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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__"
28 import TestSCons
30 _python_ = TestSCons._python_
32 test = TestSCons.TestSCons()
34 test.subdir('work1', 'work2', 'work3')
38 test.write('succeed.py', r"""
39 import sys
40 file = open(sys.argv[1], 'w')
41 file.write("succeed.py: %s\n" % sys.argv[1])
42 file.close()
43 sys.exit(0)
44 """)
46 test.write('fail.py', r"""
47 import sys
48 sys.exit(1)
49 """)
53 # Test: work1
56 test.write(['work1', 'SConstruct'], """\
57 DefaultEnvironment(tools=[])
58 Succeed = Builder(action=r'%(_python_)s ../succeed.py $TARGETS')
59 Fail = Builder(action=r'%(_python_)s ../fail.py $TARGETS')
60 env = Environment(BUILDERS={'Succeed': Succeed, 'Fail': Fail}, tools=[])
61 env.Fail(target='aaa.1', source='aaa.in')
62 env.Succeed(target='aaa.out', source='aaa.1')
63 env.Succeed(target='bbb.out', source='bbb.in')
64 """ % locals())
66 test.write(['work1', 'aaa.in'], "aaa.in\n")
67 test.write(['work1', 'bbb.in'], "bbb.in\n")
69 test.run(chdir='work1',
70 arguments='aaa.out bbb.out',
71 stderr='scons: *** [aaa.1] Error 1\n',
72 status=2)
74 test.must_not_exist(test.workpath('work1', 'aaa.1'))
75 test.must_not_exist(test.workpath('work1', 'aaa.out'))
76 test.must_not_exist(test.workpath('work1', 'bbb.out'))
78 test.run(chdir='work1',
79 arguments='-k aaa.out bbb.out',
80 stderr='scons: *** [aaa.1] Error 1\n',
81 status=2)
83 test.must_not_exist(test.workpath('work1', 'aaa.1'))
84 test.must_not_exist(test.workpath('work1', 'aaa.out'))
85 test.must_match(['work1', 'bbb.out'], "succeed.py: bbb.out\n", mode='r')
87 test.unlink(['work1', 'bbb.out'])
89 test.run(chdir = 'work1',
90 arguments='--keep-going aaa.out bbb.out',
91 stderr='scons: *** [aaa.1] Error 1\n',
92 status=2)
94 test.must_not_exist(test.workpath('work1', 'aaa.1'))
95 test.must_not_exist(test.workpath('work1', 'aaa.out'))
96 test.must_match(['work1', 'bbb.out'], "succeed.py: bbb.out\n", mode='r')
98 expect = """\
99 scons: Reading SConscript files ...
100 scons: done reading SConscript files.
101 scons: Cleaning targets ...
102 Removed bbb.out
103 scons: done cleaning targets.
106 test.run(chdir='work1',
107 arguments='--clean --keep-going aaa.out bbb.out',
108 stdout=expect)
110 test.must_not_exist(test.workpath('work1', 'aaa.1'))
111 test.must_not_exist(test.workpath('work1', 'aaa.out'))
112 test.must_not_exist(test.workpath('work1', 'bbb.out'))
117 # Test: work2
120 test.write(['work2', 'SConstruct'], """\
121 DefaultEnvironment(tools=[])
122 Succeed = Builder(action=r'%(_python_)s ../succeed.py $TARGETS')
123 Fail = Builder(action=r'%(_python_)s ../fail.py $TARGETS')
124 env = Environment(BUILDERS={'Succeed': Succeed, 'Fail': Fail}, tools=[])
125 env.Fail('aaa.out', 'aaa.in')
126 env.Succeed('bbb.out', 'aaa.out')
127 env.Succeed('ccc.out', 'ccc.in')
128 env.Succeed('ddd.out', 'ccc.in')
129 """ % locals())
131 test.write(['work2', 'aaa.in'], "aaa.in\n")
132 test.write(['work2', 'ccc.in'], "ccc.in\n")
134 test.run(chdir='work2',
135 arguments='-k .',
136 status=2,
137 stderr=None,
138 stdout="""\
139 scons: Reading SConscript files ...
140 scons: done reading SConscript files.
141 scons: Building targets ...
142 %(_python_)s ../fail.py aaa.out
143 %(_python_)s ../succeed.py ccc.out
144 %(_python_)s ../succeed.py ddd.out
145 scons: done building targets (errors occurred during build).
146 """ % locals())
148 test.must_not_exist(['work2', 'aaa.out'])
149 test.must_not_exist(['work2', 'bbb.out'])
150 test.must_match(['work2', 'ccc.out'], "succeed.py: ccc.out\n", mode='r')
151 test.must_match(['work2', 'ddd.out'], "succeed.py: ddd.out\n", mode='r')
156 # Test: work3
158 # Check that the -k (keep-going) switch works correctly when the Nodes
159 # forms a DAG. The test case is the following
161 # all
163 # +-----+-----+-------------+
164 # | | |
165 # a1 a2 a3
166 # | | |
167 # + +---+---+ +---+---+
168 # \ | / | |
169 # \ bbb.out / a4 ccc.out
170 # \ / /
171 # \ / /
172 # \ / /
173 # aaa.out (fails)
176 test.write(['work3', 'SConstruct'], """\
177 DefaultEnvironment(tools=[])
178 Succeed = Builder(action = r'%(_python_)s ../succeed.py $TARGETS')
179 Fail = Builder(action = r'%(_python_)s ../fail.py $TARGETS')
180 env = Environment(BUILDERS = {'Succeed': Succeed, 'Fail': Fail}, tools=[])
181 a = env.Fail('aaa.out', 'aaa.in')
182 b = env.Succeed('bbb.out', 'bbb.in')
183 c = env.Succeed('ccc.out', 'ccc.in')
185 a1 = Alias( 'a1', a )
186 a2 = Alias( 'a2', a+b)
187 a4 = Alias( 'a4', c)
188 a3 = Alias( 'a3', a4+c)
190 Alias('all', a1+a2+a3)
191 """ % locals())
193 test.write(['work3', 'aaa.in'], "aaa.in\n")
194 test.write(['work3', 'bbb.in'], "bbb.in\n")
195 test.write(['work3', 'ccc.in'], "ccc.in\n")
198 # Test tegular build (i.e. without -k)
199 test.run(chdir = 'work3',
200 arguments = '.',
201 status = 2,
202 stderr = None,
203 stdout = """\
204 scons: Reading SConscript files ...
205 scons: done reading SConscript files.
206 scons: Building targets ...
207 %(_python_)s ../fail.py aaa.out
208 scons: building terminated because of errors.
209 """ % locals())
211 test.must_not_exist(['work3', 'aaa.out'])
212 test.must_not_exist(['work3', 'bbb.out'])
213 test.must_not_exist(['work3', 'ccc.out'])
216 test.run(chdir = 'work3',
217 arguments = '-c .')
218 test.must_not_exist(['work3', 'aaa.out'])
219 test.must_not_exist(['work3', 'bbb.out'])
220 test.must_not_exist(['work3', 'ccc.out'])
223 # Current directory
224 test.run(chdir = 'work3',
225 arguments = '-k .',
226 status = 2,
227 stderr = None,
228 stdout = """\
229 scons: Reading SConscript files ...
230 scons: done reading SConscript files.
231 scons: Building targets ...
232 %(_python_)s ../fail.py aaa.out
233 %(_python_)s ../succeed.py bbb.out
234 %(_python_)s ../succeed.py ccc.out
235 scons: done building targets (errors occurred during build).
236 """ % locals())
238 test.must_not_exist(['work3', 'aaa.out'])
239 test.must_exist(['work3', 'bbb.out'])
240 test.must_exist(['work3', 'ccc.out'])
243 test.run(chdir = 'work3',
244 arguments = '-c .')
245 test.must_not_exist(['work3', 'aaa.out'])
246 test.must_not_exist(['work3', 'bbb.out'])
247 test.must_not_exist(['work3', 'ccc.out'])
250 # Single target
251 test.run(chdir = 'work3',
252 arguments = '--keep-going all',
253 status = 2,
254 stderr = None,
255 stdout = """\
256 scons: Reading SConscript files ...
257 scons: done reading SConscript files.
258 scons: Building targets ...
259 %(_python_)s ../fail.py aaa.out
260 %(_python_)s ../succeed.py bbb.out
261 %(_python_)s ../succeed.py ccc.out
262 scons: done building targets (errors occurred during build).
263 """ % locals())
265 test.must_not_exist(['work3', 'aaa.out'])
266 test.must_exist(['work3', 'bbb.out'])
267 test.must_exist(['work3', 'ccc.out'])
270 test.run(chdir = 'work3',
271 arguments = '-c .')
272 test.must_not_exist(['work3', 'aaa.out'])
273 test.must_not_exist(['work3', 'bbb.out'])
274 test.must_not_exist(['work3', 'ccc.out'])
277 # Separate top-level targets
278 test.run(chdir = 'work3',
279 arguments = '-k a1 a2 a3',
280 status = 2,
281 stderr = None,
282 stdout = """\
283 scons: Reading SConscript files ...
284 scons: done reading SConscript files.
285 scons: Building targets ...
286 %(_python_)s ../fail.py aaa.out
287 %(_python_)s ../succeed.py bbb.out
288 %(_python_)s ../succeed.py ccc.out
289 scons: done building targets (errors occurred during build).
290 """ % locals())
292 test.must_not_exist(['work3', 'aaa.out'])
293 test.must_exist(['work3', 'bbb.out'])
294 test.must_exist(['work3', 'ccc.out'])
297 test.pass_test()
299 # Local Variables:
300 # tab-width:4
301 # indent-tabs-mode:nil
302 # End:
303 # vim: set expandtab tabstop=4 shiftwidth=4: