Added fix for TeX includes with same name as subdirs.
[scons.git] / test / 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 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import os.path
28
29 import TestSCons
30
31 _python_ = TestSCons._python_
32
33 test = TestSCons.TestSCons()
34
35 test.subdir('work1', 'work2', 'work3')
36
37
38
39 test.write('succeed.py', r"""
40 import sys
41 file = open(sys.argv[1], 'wb')
42 file.write("succeed.py: %s\n" % sys.argv[1])
43 file.close()
44 sys.exit(0)
45 """)
46
47 test.write('fail.py', r"""
48 import sys
49 sys.exit(1)
50 """)
51
52
53 #
54 # Test: work1
55
56
57 test.write(['work1', 'SConstruct'], """\
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 })
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())
65
66 test.write(['work1', 'aaa.in'], "aaa.in\n")
67 test.write(['work1', 'bbb.in'], "bbb.in\n")
68
69 test.run(chdir = 'work1',
70          arguments = 'aaa.out bbb.out',
71          stderr = 'scons: *** [aaa.1] Error 1\n',
72          status = 2)
73
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'))
77
78 test.run(chdir = 'work1',
79          arguments = '-k aaa.out bbb.out',
80          stderr = 'scons: *** [aaa.1] Error 1\n',
81          status = 2)
82
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")
86
87 test.unlink(['work1', 'bbb.out'])
88
89 test.run(chdir = 'work1',
90          arguments = '--keep-going aaa.out bbb.out',
91          stderr = 'scons: *** [aaa.1] Error 1\n',
92          status = 2)
93
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")
97
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.
104 """
105
106 test.run(chdir = 'work1',
107          arguments = '--clean --keep-going aaa.out bbb.out',
108          stdout = expect)
109
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'))
113
114
115
116 #
117 # Test: work2
118
119
120 test.write(['work2', 'SConstruct'], """\
121 Succeed = Builder(action = r'%(_python_)s ../succeed.py $TARGETS')
122 Fail = Builder(action = r'%(_python_)s ../fail.py $TARGETS')
123 env = Environment(BUILDERS = { 'Succeed' : Succeed, 'Fail' : Fail })
124 env.Fail('aaa.out', 'aaa.in')
125 env.Succeed('bbb.out', 'aaa.out')
126 env.Succeed('ccc.out', 'ccc.in')
127 env.Succeed('ddd.out', 'ccc.in')
128 """ % locals())
129
130 test.write(['work2', 'aaa.in'], "aaa.in\n")
131 test.write(['work2', 'ccc.in'], "ccc.in\n")
132
133 test.run(chdir = 'work2',
134          arguments = '-k .',
135          status = 2,
136          stderr = None,
137          stdout = """\
138 scons: Reading SConscript files ...
139 scons: done reading SConscript files.
140 scons: Building targets ...
141 %(_python_)s ../fail.py aaa.out
142 %(_python_)s ../succeed.py ccc.out
143 %(_python_)s ../succeed.py ddd.out
144 scons: done building targets (errors occurred during build).
145 """ % locals())
146
147 test.must_not_exist(['work2', 'aaa.out'])
148 test.must_not_exist(['work2', 'bbb.out'])
149 test.must_match(['work2', 'ccc.out'], "succeed.py: ccc.out\n")
150 test.must_match(['work2', 'ddd.out'], "succeed.py: ddd.out\n")
151
152
153
154 #
155 # Test: work3
156 #
157 # Check that the -k (keep-going) switch works correctly when the Nodes
158 # forms a DAG. The test case is the following
159 #
160 #               all
161 #                |
162 #          +-----+-----+-------------+
163 #          |           |             |
164 #         a1           a2           a3
165 #          |           |             |
166 #          +       +---+---+     +---+---+ 
167 #          \       |      /      |       |
168 #           \   bbb.out  /      a4    ccc.out
169 #            \          /       /        
170 #             \        /       /  
171 #              \      /       /  
172 #              aaa.out (fails)
173 #
174
175 test.write(['work3', 'SConstruct'], """\
176 Succeed = Builder(action = r'%(_python_)s ../succeed.py $TARGETS')
177 Fail = Builder(action = r'%(_python_)s ../fail.py $TARGETS')
178 env = Environment(BUILDERS = { 'Succeed' : Succeed, 'Fail' : Fail })
179 a = env.Fail('aaa.out', 'aaa.in')
180 b = env.Succeed('bbb.out', 'bbb.in')
181 c = env.Succeed('ccc.out', 'ccc.in')
182
183 a1 = Alias( 'a1', a )
184 a2 = Alias( 'a2', a+b) 
185 a4 = Alias( 'a4', c) 
186 a3 = Alias( 'a3', a4+c) 
187
188 Alias('all', a1+a2+a3)
189 """ % locals())
190
191 test.write(['work3', 'aaa.in'], "aaa.in\n")
192 test.write(['work3', 'bbb.in'], "bbb.in\n")
193 test.write(['work3', 'ccc.in'], "ccc.in\n")
194
195
196 # Test tegular build (i.e. without -k)
197 test.run(chdir = 'work3',
198          arguments = '.',
199          status = 2,
200          stderr = None,
201          stdout = """\
202 scons: Reading SConscript files ...
203 scons: done reading SConscript files.
204 scons: Building targets ...
205 %(_python_)s ../fail.py aaa.out
206 scons: building terminated because of errors.
207 """ % locals())
208
209 test.must_not_exist(['work3', 'aaa.out'])
210 test.must_not_exist(['work3', 'bbb.out'])
211 test.must_not_exist(['work3', 'ccc.out'])
212
213
214 test.run(chdir = 'work3',
215          arguments = '-c .')
216 test.must_not_exist(['work3', 'aaa.out'])
217 test.must_not_exist(['work3', 'bbb.out'])
218 test.must_not_exist(['work3', 'ccc.out'])
219
220
221 # Current directory
222 test.run(chdir = 'work3',
223          arguments = '-k .',
224          status = 2,
225          stderr = None,
226          stdout = """\
227 scons: Reading SConscript files ...
228 scons: done reading SConscript files.
229 scons: Building targets ...
230 %(_python_)s ../fail.py aaa.out
231 %(_python_)s ../succeed.py bbb.out
232 %(_python_)s ../succeed.py ccc.out
233 scons: done building targets (errors occurred during build).
234 """ % locals())
235
236 test.must_not_exist(['work3', 'aaa.out'])
237 test.must_exist(['work3', 'bbb.out'])
238 test.must_exist(['work3', 'ccc.out'])
239
240
241 test.run(chdir = 'work3',
242          arguments = '-c .')
243 test.must_not_exist(['work3', 'aaa.out'])
244 test.must_not_exist(['work3', 'bbb.out'])
245 test.must_not_exist(['work3', 'ccc.out'])
246
247
248 # Single target
249 test.run(chdir = 'work3',
250          arguments = '--keep-going all',
251          status = 2,
252          stderr = None,
253          stdout = """\
254 scons: Reading SConscript files ...
255 scons: done reading SConscript files.
256 scons: Building targets ...
257 %(_python_)s ../fail.py aaa.out
258 %(_python_)s ../succeed.py bbb.out
259 %(_python_)s ../succeed.py ccc.out
260 scons: done building targets (errors occurred during build).
261 """ % locals())
262
263 test.must_not_exist(['work3', 'aaa.out'])
264 test.must_exist(['work3', 'bbb.out'])
265 test.must_exist(['work3', 'ccc.out'])
266
267
268 test.run(chdir = 'work3',
269          arguments = '-c .')
270 test.must_not_exist(['work3', 'aaa.out'])
271 test.must_not_exist(['work3', 'bbb.out'])
272 test.must_not_exist(['work3', 'ccc.out'])
273
274
275 # Separate top-level targets
276 test.run(chdir = 'work3',
277          arguments = '-k a1 a2 a3',
278          status = 2,
279          stderr = None,
280          stdout = """\
281 scons: Reading SConscript files ...
282 scons: done reading SConscript files.
283 scons: Building targets ...
284 %(_python_)s ../fail.py aaa.out
285 %(_python_)s ../succeed.py bbb.out
286 %(_python_)s ../succeed.py ccc.out
287 scons: done building targets (errors occurred during build).
288 """ % locals())
289
290 test.must_not_exist(['work3', 'aaa.out'])
291 test.must_exist(['work3', 'bbb.out'])
292 test.must_exist(['work3', 'ccc.out'])
293
294
295 test.pass_test()
296
297 # Local Variables:
298 # tab-width:4
299 # indent-tabs-mode:nil
300 # End:
301 # vim: set expandtab tabstop=4 shiftwidth=4: