Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Default.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 """
28 Verify various combinations of arguments to Default() work properly.
29 """
30
31 import os
32
33 import TestSCons
34
35 _python_ = TestSCons._python_
36
37 test = TestSCons.TestSCons()
38
39 for dir in ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight']:
40
41     test.subdir(dir)
42
43     test.write(os.path.join(dir, 'foo.in'), dir + "/foo.in\n");
44
45     test.write(os.path.join(dir, 'bar.in'), dir + "/bar.in\n");
46
47 test.write('build.py', r"""
48 import sys
49 contents = open(sys.argv[2], 'rb').read()
50 file = open(sys.argv[1], 'wb')
51 file.write(contents)
52 file.close()
53 """)
54
55 #
56 test.write(['one', 'SConstruct'], """
57 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
58 env = Environment(BUILDERS = { 'B' : B })
59 env.B(target = 'foo.out', source = 'foo.in')
60 env.B(target = 'bar.out', source = 'bar.in')
61 Default('foo.out')
62 """ % locals())
63
64 test.write(['two', 'SConstruct'], """
65 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
66 env = Environment(BUILDERS = { 'B' : B })
67 env.B(target = 'foo.out', source = 'foo.in')
68 env.B(target = 'bar.out', source = 'bar.in')
69 Default('foo.out', 'bar.out')
70 """ % locals())
71
72 test.write(['three', 'SConstruct'], """
73 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
74 env = Environment(BUILDERS = { 'B' : B })
75 env.B(target = 'foo.out', source = 'foo.in')
76 env.B(target = 'bar.out', source = 'bar.in')
77 Default(Split('foo.out bar.out'))
78 """ % locals())
79
80 test.write(['four', 'SConstruct'], """
81 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
82 env = Environment(BUILDERS = { 'B' : B })
83 env.B(target = ['foo bar'], source = 'foo.in')
84 env.B(target = 'foo', source = 'foo.in')
85 env.B(target = 'bar', source = 'bar.in')
86 Default(['foo bar'])
87 """ % locals())
88
89 test.write(['five', 'SConstruct'], """
90 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
91 env = Environment(BUILDERS = { 'B' : B })
92 Default(env.B(target = 'foo.out', source = 'foo.in'))
93 Default(env.B(target = 'bar.out', source = 'bar.in'))
94 """ % locals())
95
96
97 for dir in ['one', 'two', 'three', 'four', 'five']:
98
99     test.run(chdir = dir)       # no arguments, use the Default
100
101 test.fail_test(test.read(test.workpath('one', 'foo.out')) != "one/foo.in\n")
102 test.fail_test(os.path.exists(test.workpath('one', 'bar')))
103
104 test.fail_test(test.read(test.workpath('two', 'foo.out')) != "two/foo.in\n")
105 test.fail_test(test.read(test.workpath('two', 'bar.out')) != "two/bar.in\n")
106
107 test.fail_test(test.read(test.workpath('three', 'foo.out')) != "three/foo.in\n")
108 test.fail_test(test.read(test.workpath('three', 'bar.out')) != "three/bar.in\n")
109
110 test.fail_test(os.path.exists(test.workpath('four', 'foo')))
111 test.fail_test(os.path.exists(test.workpath('four', 'bar')))
112 test.fail_test(test.read(test.workpath('four', 'foo bar')) != "four/foo.in\n")
113
114 test.fail_test(test.read(test.workpath('five', 'foo.out')) != "five/foo.in\n")
115 test.fail_test(test.read(test.workpath('five', 'bar.out')) != "five/bar.in\n")
116
117
118
119 # Test how a None Default() argument works to disable/reset default targets.
120 test.write(['six', 'SConstruct'], """\
121 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
122 env = Environment(BUILDERS = { 'B' : B })
123 foo = env.B(target = 'foo.out', source = 'foo.in')
124 bar = env.B(target = 'bar.out', source = 'bar.in')
125 Default(None)
126 """ % locals())
127
128 test.run(chdir = 'six', status = 2, stderr =
129 "scons: *** No targets specified and no Default() targets found.  Stop.\n")
130
131 test.write(['seven', 'SConstruct'], """\
132 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
133 env = Environment(BUILDERS = { 'B' : B })
134 foo = env.B(target = 'foo.out', source = 'foo.in')
135 bar = env.B(target = 'bar.out', source = 'bar.in')
136 Default(foo, bar, None)
137 """ % locals())
138
139 test.run(chdir = 'seven', status = 2, stderr =
140 "scons: *** No targets specified and no Default() targets found.  Stop.\n")
141
142 test.write(['eight', 'SConstruct'], """\
143 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
144 env = Environment(BUILDERS = { 'B' : B })
145 foo = env.B(target = 'foo.out', source = 'foo.in')
146 bar = env.B(target = 'bar.out', source = 'bar.in')
147 Default(foo, None, bar)
148 """ % locals())
149
150 test.run(chdir = 'eight')       # no arguments, use the Default
151
152 test.fail_test(os.path.exists(test.workpath('eight', 'foo.out')))
153 test.fail_test(test.read(test.workpath('eight', 'bar.out')) != "eight/bar.in\n")
154
155
156
157
158 test.subdir('nine', ['nine', 'sub1'])
159
160 test.write(['nine', 'SConstruct'], """\
161 B = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES')
162 env = Environment(BUILDERS = { 'B' : B })
163 env.B(target = 'xxx.out', source = 'xxx.in')
164 SConscript('sub1/SConscript')
165 """ % locals())
166
167 test.write(['nine', 'xxx.in'], "xxx.in\n")
168
169 test.write(['nine', 'sub1', 'SConscript'], """
170 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
171 env = Environment(BUILDERS = { 'B' : B })
172 env.B(target = 'xxx.out', source = 'xxx.in')
173 Default('xxx.out')
174 """ % locals())
175
176 test.write(['nine', 'sub1', 'xxx.in'], "sub1/xxx.in\n")
177
178 test.run(chdir = 'nine')        # no arguments, use the Default
179
180 test.fail_test(os.path.exists(test.workpath('nine', 'xxx.out')))
181 test.fail_test(test.read(test.workpath('nine', 'sub1', 'xxx.out')) != "sub1/xxx.in\n")
182
183
184
185 test.subdir('ten', ['ten', 'sub2'])
186
187 test.write(['ten', 'SConstruct'], """\
188 Default('sub2')
189 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
190 env = Environment(BUILDERS = { 'B' : B })
191 env.B(target = 'xxx.out', source = 'xxx.in')
192 SConscript('sub2/SConscript')
193 """ % locals())
194
195 test.write(['ten', 'xxx.in'], "xxx.in\n")
196
197 test.write(['ten', 'sub2', 'SConscript'], """
198 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
199 env = Environment(BUILDERS = { 'B' : B })
200 env.B(target = 'xxx.out', source = 'xxx.in')
201 """ % locals())
202
203 test.write(['ten', 'sub2', 'xxx.in'], "sub2/xxx.in\n")
204
205 test.run(chdir = 'ten') # no arguments, use the Default
206
207 test.fail_test(os.path.exists(test.workpath('ten', 'xxx.out')))
208 test.fail_test(test.read(test.workpath('ten', 'sub2', 'xxx.out')) != "sub2/xxx.in\n")
209
210
211 test.subdir('eleven')
212
213 test.write(['eleven', 'SConstruct'], """
214 B = Builder(action = r'%(_python_)s ../build.py $TARGET $SOURCES')
215 env = Environment(BUILDERS = { 'B' : B }, XXX = 'foo.out')
216 env.B(target = 'foo.out', source = 'foo.in')
217 env.B(target = 'bar.out', source = 'bar.in')
218 env.Default('$XXX')
219 """ % locals())
220
221 test.write(os.path.join('eleven', 'foo.in'), "eleven/foo.in\n");
222
223 test.write(os.path.join('eleven', 'bar.in'), "eleven/bar.in\n");
224
225 test.run(chdir = 'eleven')      # no arguments, use the Default
226
227 test.fail_test(test.read(test.workpath('eleven', 'foo.out')) != "eleven/foo.in\n")
228 test.fail_test(os.path.exists(test.workpath('eleven', 'bar')))
229
230
231
232 test.pass_test()
233
234 # Local Variables:
235 # tab-width:4
236 # indent-tabs-mode:nil
237 # End:
238 # vim: set expandtab tabstop=4 shiftwidth=4: