Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Program.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 import time
29
30 import TestSCons
31
32 _exe = TestSCons._exe
33
34 test = TestSCons.TestSCons()
35
36 foo1 = test.workpath('foo1' + _exe)
37 foo2 = test.workpath('foo2' + _exe)
38 foo3 = test.workpath('foo3' + _exe)
39 foo4 = test.workpath('foo4' + _exe)
40 foo5 = test.workpath('foo5' + _exe)
41 foo_args = 'foo1%s foo2%s foo3%s foo4%s foo5%s' % (_exe, _exe, _exe, _exe, _exe)
42
43 test.write('SConstruct', """
44 env = Environment()
45 env.Program(target = 'foo1', source = 'f1.c')
46 env.Program(target = 'foo2', source = Split('f2a.c f2b.c f2c.c'))
47 f3a = File('f3a.c')
48 f3b = File('f3b.c')
49 Program(target = 'foo3', source = [f3a, [f3b, 'f3c.c']])
50 env.Program('foo4', 'f4.c')
51 env.Program('foo5.c')
52 """)
53
54 test.write('f1.c', r"""
55 #include <stdio.h>
56 #include <stdlib.h>
57 int
58 main(int argc, char *argv[])
59 {
60         argv[argc++] = "--";
61         printf("f1.c\n");
62         exit (0);
63 }
64 """)
65
66 test.write('f2a.c', r"""
67 #include <stdio.h>
68 #include <stdlib.h>
69 void
70 f2a(void)
71 {
72         printf("f2a.c\n");
73 }
74 """)
75
76 test.write('f2b.c', r"""
77 #include <stdio.h>
78 void
79 f2b(void)
80 {
81         printf("f2b.c\n");
82 }
83 """)
84
85 test.write('f2c.c', r"""
86 #include <stdio.h>
87 #include <stdlib.h>
88 extern void f2a(void);
89 extern void f2b(void);
90 int
91 main(int argc, char *argv[])
92 {
93         argv[argc++] = "--";
94         f2a();
95         f2b();
96         printf("f2c.c\n");
97         exit (0);
98 }
99 """)
100
101 test.write('f3a.c', r"""
102 #include <stdio.h>
103 void
104 f3a(void)
105 {
106         printf("f3a.c\n");
107 }
108 """)
109
110 test.write('f3b.c', r"""
111 #include <stdio.h>
112 void
113 f3b(void)
114 {
115         printf("f3b.c\n");
116 }
117 """)
118
119 test.write('f3c.c', r"""
120 #include <stdio.h>
121 #include <stdlib.h>
122 extern void f3a(void);
123 extern void f3b(void);
124 int
125 main(int argc, char *argv[])
126 {
127         argv[argc++] = "--";
128         f3a();
129         f3b();
130         printf("f3c.c\n");
131         exit (0);
132 }
133 """)
134
135 test.write('f4.c', r"""
136 #include <stdio.h>
137 #include <stdlib.h>
138 int
139 main(int argc, char *argv[])
140 {
141         argv[argc++] = "--";
142         printf("f4.c\n");
143         exit (0);
144 }
145 """)
146
147 test.write('foo5.c', r"""
148 #include <stdio.h>
149 #include <stdlib.h>
150 int
151 main(int argc, char *argv[])
152 {
153         argv[argc++] = "--";
154         printf("foo5.c\n");
155         exit (0);
156 }
157 """)
158
159 test.run(arguments = '.')
160
161 test.run(program = foo1, stdout = "f1.c\n")
162 test.run(program = foo2, stdout = "f2a.c\nf2b.c\nf2c.c\n")
163 test.run(program = foo3, stdout = "f3a.c\nf3b.c\nf3c.c\n")
164 test.run(program = foo4, stdout = "f4.c\n")
165 test.run(program = foo5, stdout = "foo5.c\n")
166
167 test.up_to_date(arguments = '.')
168
169 test.write('f1.c', r"""
170 #include <stdio.h>
171 #include <stdlib.h>
172 int
173 main(int argc, char *argv[])
174 {
175         argv[argc++] = "--";
176         printf("f1.c X\n");
177         exit (0);
178 }
179 """)
180
181 test.write('f3b.c', r"""
182 #include <stdio.h>
183 void
184 f3b(void)
185 {
186         printf("f3b.c X\n");
187 }
188 """)
189
190 test.write('f4.c', r"""
191 #include <stdio.h>
192 #include <stdlib.h>
193 int
194 main(int argc, char *argv[])
195 {
196         argv[argc++] = "--";
197         printf("f4.c X\n");
198         exit (0);
199 }
200 """)
201
202 test.write('foo5.c', r"""
203 #include <stdio.h>
204 #include <stdlib.h>
205 int
206 main(int argc, char *argv[])
207 {
208         argv[argc++] = "--";
209         printf("foo5.c X\n");
210         exit (0);
211 }
212 """)
213
214 test.run(arguments = '.')
215
216 test.run(program = foo1, stdout = "f1.c X\n")
217 test.run(program = foo2, stdout = "f2a.c\nf2b.c\nf2c.c\n")
218 test.run(program = foo3, stdout = "f3a.c\nf3b.c X\nf3c.c\n")
219 test.run(program = foo4, stdout = "f4.c X\n")
220 test.run(program = foo5, stdout = "foo5.c X\n")
221
222 test.up_to_date(arguments = '.')
223
224 # make sure the programs didn't get rebuilt, because nothing changed:
225 oldtime1 = os.path.getmtime(foo1)
226 oldtime2 = os.path.getmtime(foo2)
227 oldtime3 = os.path.getmtime(foo3)
228 oldtime4 = os.path.getmtime(foo4)
229 oldtime5 = os.path.getmtime(foo5)
230
231 time.sleep(2) # introduce a small delay, to make the test valid
232
233 test.run(arguments = foo_args)
234
235 test.fail_test(oldtime1 != os.path.getmtime(foo1))
236 test.fail_test(oldtime2 != os.path.getmtime(foo2))
237 test.fail_test(oldtime3 != os.path.getmtime(foo3))
238 test.fail_test(oldtime4 != os.path.getmtime(foo4))
239 test.fail_test(oldtime5 != os.path.getmtime(foo5))
240
241 test.write('f1.c', r"""
242 #include <stdio.h>
243 #include <stdlib.h>
244 int
245 main(int argc, char *argv[])
246 {
247         argv[argc++] = "--";
248         printf("f1.c Y\n");
249         exit (0);
250 }
251 """)
252
253 test.write('f3b.c', r"""
254 #include <stdio.h>
255 #include <stdlib.h>
256 void
257 f3b(void)
258 {
259         printf("f3b.c Y\n");
260 }
261 """)
262
263 test.write('f4.c', r"""
264 #include <stdio.h>
265 #include <stdlib.h>
266 int
267 main(int argc, char *argv[])
268 {
269         argv[argc++] = "--";
270         printf("f4.c Y\n");
271         exit (0);
272 }
273 """)
274
275 test.write('foo5.c', r"""
276 #include <stdio.h>
277 #include <stdlib.h>
278 int
279 main(int argc, char *argv[])
280 {
281         argv[argc++] = "--";
282         printf("foo5.c Y\n");
283         exit (0);
284 }
285 """)
286
287 test.run(arguments = foo_args)
288
289 test.run(program = foo1, stdout = "f1.c Y\n")
290 test.run(program = foo2, stdout = "f2a.c\nf2b.c\nf2c.c\n")
291 test.run(program = foo3, stdout = "f3a.c\nf3b.c Y\nf3c.c\n")
292 test.run(program = foo4, stdout = "f4.c Y\n")
293 test.run(program = foo5, stdout = "foo5.c Y\n")
294
295 test.up_to_date(arguments = foo_args)
296
297 test.write('f1.c', r"""
298 #include <stdio.h>
299 #include <stdlib.h>
300 int
301 main(int argc, char *argv[])
302 {
303         argv[argc++] = "--";
304         printf("f1.c Z\n");
305         exit (0);
306 }
307 """)
308
309 test.write('f3b.c', r"""
310 #include <stdio.h>
311 #include <stdlib.h>
312 void
313 f3b(void)
314 {
315         printf("f3b.c Z\n");
316 }
317 """)
318
319 test.write('f4.c', r"""
320 #include <stdio.h>
321 #include <stdlib.h>
322 int
323 main(int argc, char *argv[])
324 {
325         argv[argc++] = "--";
326         printf("f4.c Z\n");
327         exit (0);
328 }
329 """)
330
331 test.write('foo5.c', r"""
332 #include <stdio.h>
333 #include <stdlib.h>
334 int
335 main(int argc, char *argv[])
336 {
337         argv[argc++] = "--";
338         printf("foo5.c Z\n");
339         exit (0);
340 }
341 """)
342
343 test.run(arguments = foo_args)
344
345 test.run(program = foo1, stdout = "f1.c Z\n")
346 test.run(program = foo2, stdout = "f2a.c\nf2b.c\nf2c.c\n")
347 test.run(program = foo3, stdout = "f3a.c\nf3b.c Z\nf3c.c\n")
348 test.run(program = foo4, stdout = "f4.c Z\n")
349 test.run(program = foo5, stdout = "foo5.c Z\n")
350
351 test.up_to_date(arguments = foo_args)
352
353 # make sure the programs didn't get rebuilt, because nothing changed:
354 oldtime1 = os.path.getmtime(foo1)
355 oldtime2 = os.path.getmtime(foo2)
356 oldtime3 = os.path.getmtime(foo3)
357 oldtime4 = os.path.getmtime(foo4)
358 oldtime5 = os.path.getmtime(foo5)
359
360 time.sleep(2) # introduce a small delay, to make the test valid
361
362 test.run(arguments = foo_args)
363
364 test.fail_test(not (oldtime1 == os.path.getmtime(foo1)))
365 test.fail_test(not (oldtime2 == os.path.getmtime(foo2)))
366 test.fail_test(not (oldtime3 == os.path.getmtime(foo3)))
367 test.fail_test(not (oldtime4 == os.path.getmtime(foo4)))
368 test.fail_test(not (oldtime5 == os.path.getmtime(foo5)))
369
370 test.pass_test()
371
372 # Local Variables:
373 # tab-width:4
374 # indent-tabs-mode:nil
375 # End:
376 # vim: set expandtab tabstop=4 shiftwidth=4: