Small docstring update for vars.Add
[scons.git] / test / Program.py
blobd977befb1aedb75dc88cc763e4a08ee0132a6c8f
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 import os.path
27 import time
29 import TestSCons
31 _exe = TestSCons._exe
33 test = TestSCons.TestSCons()
35 foo1 = test.workpath('foo1' + _exe)
36 foo2 = test.workpath('foo2' + _exe)
37 foo3 = test.workpath('foo3' + _exe)
38 foo4 = test.workpath('foo4' + _exe)
39 foo5 = test.workpath('foo5' + _exe)
40 foo_args = 'foo1%s foo2%s foo3%s foo4%s foo5%s' % (_exe, _exe, _exe, _exe, _exe)
42 test.write('SConstruct', """\
43 DefaultEnvironment(tools=[]) # test speedup
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 env.Program(target='foo3', source=[f3a, [f3b, 'f3c.c']])
50 env.Program('foo4', 'f4.c')
51 env.Program('foo5.c')
52 """)
54 test.write('f1.c', r"""
55 #include <stdio.h>
56 #include <stdlib.h>
57 int
58 main(int argc, char *argv[])
60 argv[argc++] = "--";
61 printf("f1.c\n");
62 exit (0);
64 """)
66 test.write('f2a.c', r"""
67 #include <stdio.h>
68 #include <stdlib.h>
69 void
70 f2a(void)
72 printf("f2a.c\n");
74 """)
76 test.write('f2b.c', r"""
77 #include <stdio.h>
78 void
79 f2b(void)
81 printf("f2b.c\n");
83 """)
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[])
93 argv[argc++] = "--";
94 f2a();
95 f2b();
96 printf("f2c.c\n");
97 exit (0);
99 """)
101 test.write('f3a.c', r"""
102 #include <stdio.h>
103 void
104 f3a(void)
106 printf("f3a.c\n");
108 """)
110 test.write('f3b.c', r"""
111 #include <stdio.h>
112 void
113 f3b(void)
115 printf("f3b.c\n");
117 """)
119 test.write('f3c.c', r"""
120 #include <stdio.h>
121 #include <stdlib.h>
122 extern void f3a(void);
123 extern void f3b(void);
125 main(int argc, char *argv[])
127 argv[argc++] = "--";
128 f3a();
129 f3b();
130 printf("f3c.c\n");
131 exit (0);
133 """)
135 test.write('f4.c', r"""
136 #include <stdio.h>
137 #include <stdlib.h>
139 main(int argc, char *argv[])
141 argv[argc++] = "--";
142 printf("f4.c\n");
143 exit (0);
145 """)
147 test.write('foo5.c', r"""
148 #include <stdio.h>
149 #include <stdlib.h>
151 main(int argc, char *argv[])
153 argv[argc++] = "--";
154 printf("foo5.c\n");
155 exit (0);
157 """)
159 test.run(arguments='.')
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 test.up_to_date(arguments='.')
168 test.write('f1.c', r"""
169 #include <stdio.h>
170 #include <stdlib.h>
172 main(int argc, char *argv[])
174 argv[argc++] = "--";
175 printf("f1.c X\n");
176 exit (0);
178 """)
180 test.write('f3b.c', r"""
181 #include <stdio.h>
182 void
183 f3b(void)
185 printf("f3b.c X\n");
187 """)
189 test.write('f4.c', r"""
190 #include <stdio.h>
191 #include <stdlib.h>
193 main(int argc, char *argv[])
195 argv[argc++] = "--";
196 printf("f4.c X\n");
197 exit (0);
199 """)
201 test.write('foo5.c', r"""
202 #include <stdio.h>
203 #include <stdlib.h>
205 main(int argc, char *argv[])
207 argv[argc++] = "--";
208 printf("foo5.c X\n");
209 exit (0);
211 """)
213 test.run(arguments='.')
215 test.run(program=foo1, stdout="f1.c X\n")
216 test.run(program=foo2, stdout="f2a.c\nf2b.c\nf2c.c\n")
217 test.run(program=foo3, stdout="f3a.c\nf3b.c X\nf3c.c\n")
218 test.run(program=foo4, stdout="f4.c X\n")
219 test.run(program=foo5, stdout="foo5.c X\n")
220 test.up_to_date(arguments='.')
222 # make sure the programs didn't get rebuilt, because nothing changed:
223 oldtime1 = os.path.getmtime(foo1)
224 oldtime2 = os.path.getmtime(foo2)
225 oldtime3 = os.path.getmtime(foo3)
226 oldtime4 = os.path.getmtime(foo4)
227 oldtime5 = os.path.getmtime(foo5)
229 test.sleep() # delay for timestamps
230 test.run(arguments=foo_args)
231 test.fail_test(oldtime1 != os.path.getmtime(foo1))
232 test.fail_test(oldtime2 != os.path.getmtime(foo2))
233 test.fail_test(oldtime3 != os.path.getmtime(foo3))
234 test.fail_test(oldtime4 != os.path.getmtime(foo4))
235 test.fail_test(oldtime5 != os.path.getmtime(foo5))
237 test.write('f1.c', r"""
238 #include <stdio.h>
239 #include <stdlib.h>
241 main(int argc, char *argv[])
243 argv[argc++] = "--";
244 printf("f1.c Y\n");
245 exit (0);
247 """)
249 test.write('f3b.c', r"""
250 #include <stdio.h>
251 #include <stdlib.h>
252 void
253 f3b(void)
255 printf("f3b.c Y\n");
257 """)
259 test.write('f4.c', r"""
260 #include <stdio.h>
261 #include <stdlib.h>
263 main(int argc, char *argv[])
265 argv[argc++] = "--";
266 printf("f4.c Y\n");
267 exit (0);
269 """)
271 test.write('foo5.c', r"""
272 #include <stdio.h>
273 #include <stdlib.h>
275 main(int argc, char *argv[])
277 argv[argc++] = "--";
278 printf("foo5.c Y\n");
279 exit (0);
281 """)
283 test.run(arguments=foo_args)
285 test.run(program=foo1, stdout="f1.c Y\n")
286 test.run(program=foo2, stdout="f2a.c\nf2b.c\nf2c.c\n")
287 test.run(program=foo3, stdout="f3a.c\nf3b.c Y\nf3c.c\n")
288 test.run(program=foo4, stdout="f4.c Y\n")
289 test.run(program=foo5, stdout="foo5.c Y\n")
290 test.up_to_date(arguments=foo_args)
292 test.write('f1.c', r"""
293 #include <stdio.h>
294 #include <stdlib.h>
296 main(int argc, char *argv[])
298 argv[argc++] = "--";
299 printf("f1.c Z\n");
300 exit (0);
302 """)
304 test.write('f3b.c', r"""
305 #include <stdio.h>
306 #include <stdlib.h>
307 void
308 f3b(void)
310 printf("f3b.c Z\n");
312 """)
314 test.write('f4.c', r"""
315 #include <stdio.h>
316 #include <stdlib.h>
318 main(int argc, char *argv[])
320 argv[argc++] = "--";
321 printf("f4.c Z\n");
322 exit (0);
324 """)
326 test.write('foo5.c', r"""
327 #include <stdio.h>
328 #include <stdlib.h>
330 main(int argc, char *argv[])
332 argv[argc++] = "--";
333 printf("foo5.c Z\n");
334 exit (0);
336 """)
338 test.run(arguments=foo_args)
340 test.run(program=foo1, stdout="f1.c Z\n")
341 test.run(program=foo2, stdout="f2a.c\nf2b.c\nf2c.c\n")
342 test.run(program=foo3, stdout="f3a.c\nf3b.c Z\nf3c.c\n")
343 test.run(program=foo4, stdout="f4.c Z\n")
344 test.run(program=foo5, stdout="foo5.c Z\n")
345 test.up_to_date(arguments=foo_args)
347 # make sure the programs didn't get rebuilt, because nothing changed:
348 oldtime1 = os.path.getmtime(foo1)
349 oldtime2 = os.path.getmtime(foo2)
350 oldtime3 = os.path.getmtime(foo3)
351 oldtime4 = os.path.getmtime(foo4)
352 oldtime5 = os.path.getmtime(foo5)
354 test.sleep() # delay for timestamps
355 test.run(arguments=foo_args)
356 test.fail_test(not (oldtime1 == os.path.getmtime(foo1)))
357 test.fail_test(not (oldtime2 == os.path.getmtime(foo2)))
358 test.fail_test(not (oldtime3 == os.path.getmtime(foo3)))
359 test.fail_test(not (oldtime4 == os.path.getmtime(foo4)))
360 test.fail_test(not (oldtime5 == os.path.getmtime(foo5)))
362 test.pass_test()
364 # Local Variables:
365 # tab-width:4
366 # indent-tabs-mode:nil
367 # End:
368 # vim: set expandtab tabstop=4 shiftwidth=4: