Fix the test on all Python versions (failed on versions before 2.5 due
[scons.git] / test / option--Y.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 sys
28 import TestSCons
29
30 if sys.platform == 'win32':
31     _exe = '.exe'
32 else:
33     _exe = ''
34
35
36
37 test = TestSCons.TestSCons()
38
39 test.subdir('repository', 'work1')
40
41 repository = test.workpath('repository')
42 repository_foo_c = test.workpath('repository', 'foo.c')
43 work1_foo = test.workpath('work1', 'foo' + _exe)
44 work1_foo_c = test.workpath('work1', 'foo.c')
45
46 test.write(['repository', 'SConstruct'], r"""
47 env = Environment()
48 env.Program(target= 'foo', source = Split('aaa.c bbb.c foo.c'))
49 """)
50
51 test.write(['repository', 'aaa.c'], r"""
52 #include <stdio.h>
53 void
54 aaa(void)
55 {
56       printf("repository/aaa.c\n");
57 }
58 """)
59
60 test.write(['repository', 'bbb.c'], r"""
61 #include <stdio.h>
62 void
63 bbb(void)
64 {
65       printf("repository/bbb.c\n");
66 }
67 """)
68
69 test.write(['repository', 'foo.c'], r"""
70 #include <stdio.h>
71 #include <stdlib.h>
72 extern void aaa(void);
73 extern void bbb(void);
74 int
75 main(int argc, char *argv[])
76 {
77       argv[argc++] = "--";
78       aaa();
79       bbb();
80       printf("repository/foo.c\n");
81       exit (0);
82 }
83 """)
84
85 opts = '-Y ' + repository
86
87 # Make the entire repository non-writable, so we'll detect
88 # if we try to write into it accidentally.
89 test.writable('repository', 0)
90
91 test.run(chdir = 'work1', options = opts, arguments = '.')
92
93 test.run(program = work1_foo, stdout = """repository/aaa.c
94 repository/bbb.c
95 repository/foo.c
96 """)
97
98 test.up_to_date(chdir = 'work1', options = opts, arguments = '.')
99
100 #
101 test.write(['work1', 'bbb.c'], r"""
102 #include <stdio.h>
103 #include <stdlib.h>
104 void
105 bbb(void)
106 {
107       printf("work1/bbb.c\n");
108 }
109 """)
110
111 test.run(chdir = 'work1', options = opts, arguments = '.')
112
113 test.run(program = work1_foo, stdout = """repository/aaa.c
114 work1/bbb.c
115 repository/foo.c
116 """)
117
118 test.up_to_date(chdir = 'work1', options = opts, arguments = '.')
119
120 #
121 test.write(['work1', 'aaa.c'], r"""
122 #include <stdio.h>
123 #include <stdlib.h>
124 void
125 aaa(void)
126 {
127       printf("work1/aaa.c\n");
128 }
129 """)
130
131 test.write(['work1', 'foo.c'], r"""
132 #include <stdio.h>
133 #include <stdlib.h>
134 extern void aaa(void);
135 extern void bbb(void);
136 int
137 main(int argc, char *argv[])
138 {
139       argv[argc++] = "--";
140       aaa();
141       bbb();
142       printf("work1/foo.c\n");
143       exit (0);
144 }
145 """)
146
147 test.run(chdir = 'work1', options = opts, arguments = '.')
148
149 test.run(program = work1_foo, stdout = """work1/aaa.c
150 work1/bbb.c
151 work1/foo.c
152 """)
153
154 test.up_to_date(chdir = 'work1', options = opts, arguments = '.')
155
156 #
157 test.unlink(['work1', 'bbb.c'])
158 test.unlink(['work1', 'foo.c'])
159
160 test.run(chdir = 'work1', options = opts, arguments = '.')
161
162 test.run(program = work1_foo, stdout = """work1/aaa.c
163 repository/bbb.c
164 repository/foo.c
165 """)
166
167 test.up_to_date(chdir = 'work1', options = opts, arguments = '.')
168
169
170
171 #
172 test.subdir('r.NEW', 'r.OLD', 'work2')
173
174 workpath_r_NEW = test.workpath('r.NEW')
175 workpath_r_OLD = test.workpath('r.OLD')
176 work2_foo = test.workpath('work2', 'foo' + _exe)
177
178 SConstruct = """
179 env = Environment()
180 env.Program(target = 'foo', source = 'foo.c')
181 """
182
183 test.write(['r.OLD', 'SConstruct'], SConstruct)
184
185 test.write(['r.NEW', 'SConstruct'], SConstruct)
186
187 test.write(['r.OLD', 'foo.c'], r"""
188 #include <stdio.h>
189 #include <stdlib.h>
190 int
191 main(int argc, char *argv[])
192 {
193       argv[argc++] = "--";
194       printf("r.OLD/foo.c\n");
195       exit (0);
196 }
197 """)
198
199 opts = '-Y %s -Y %s' % (workpath_r_NEW, workpath_r_OLD)
200
201 # Make the repositories non-writable, so we'll detect
202 # if we try to write into them accidentally.
203 test.writable('r.OLD', 0)
204 test.writable('r.NEW', 0)
205
206 test.run(chdir = 'work2', options = opts, arguments = '.')
207
208 test.run(program = work2_foo, stdout = "r.OLD/foo.c\n")
209
210 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
211
212 #
213 test.writable('r.NEW', 1)
214
215 test.write(['r.NEW', 'foo.c'], r"""
216 #include <stdio.h>
217 #include <stdlib.h>
218 int
219 main(int argc, char *argv[])
220 {
221       argv[argc++] = "--";
222       printf("r.NEW/foo.c\n");
223       exit (0);
224 }
225 """)
226
227 test.writable('r.NEW', 0)
228
229 test.run(chdir = 'work2', options = opts, arguments = '.')
230
231 test.run(program = work2_foo, stdout = "r.NEW/foo.c\n")
232
233 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
234
235 #
236 test.write(['work2', 'foo.c'], r"""
237 #include <stdio.h>
238 #include <stdlib.h>
239 int
240 main(int argc, char *argv[])
241 {
242       argv[argc++] = "--";
243       printf("work2/foo.c\n");
244       exit (0);
245 }
246 """)
247
248 test.run(chdir = 'work2', options = opts, arguments = '.')
249
250 test.run(program = work2_foo, stdout = "work2/foo.c\n")
251
252 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
253
254 #
255 test.writable('r.OLD', 1)
256 test.writable('r.NEW', 1)
257
258 test.write(['r.OLD', 'foo.c'], r"""
259 #include <stdio.h>
260 #include <stdlib.h>
261 int
262 main(int argc, char *argv[])
263 {
264       argv[argc++] = "--";
265       printf("r.OLD/foo.c 2\n");
266       exit (0);
267 }
268 """)
269
270 test.write(['r.NEW', 'foo.c'], r"""
271 #include <stdio.h>
272 #include <stdlib.h>
273 int
274 main(int argc, char *argv[])
275 {
276       argv[argc++] = "--";
277       printf("r.NEW/foo.c 2\n");
278       exit (0);
279 }
280 """)
281
282 test.writable('r.OLD', 0)
283 test.writable('r.NEW', 0)
284
285 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
286
287 #
288 test.unlink(['work2', 'foo.c'])
289
290 test.run(chdir = 'work2', options = opts, arguments = '.')
291
292 test.run(program = work2_foo, stdout = "r.NEW/foo.c 2\n")
293
294 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
295
296 #
297 test.writable('r.NEW', 1)
298
299 test.unlink(['r.NEW', 'foo.c'])
300
301 test.writable('r.NEW', 0)
302
303 test.run(chdir = 'work2', options = opts, arguments = '.')
304
305 test.run(program = work2_foo, stdout = "r.OLD/foo.c 2\n")
306
307 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
308
309
310
311 #
312 test.pass_test()
313
314 # Local Variables:
315 # tab-width:4
316 # indent-tabs-mode:nil
317 # End:
318 # vim: set expandtab tabstop=4 shiftwidth=4: