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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
28 Verify various combinations of arguments to Default() work properly.
35 _python_ = TestSCons._python_
37 test = TestSCons.TestSCons()
39 for dir in ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight']:
43 test.write(os.path.join(dir, 'foo.in'), dir + "/foo.in\n");
45 test.write(os.path.join(dir, 'bar.in'), dir + "/bar.in\n");
47 test.write('build.py', r"""
49 contents = open(sys.argv[2], 'rb').read()
50 file = open(sys.argv[1], 'wb')
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')
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')
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'))
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')
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'))
97 for dir in ['one', 'two', 'three', 'four', 'five']:
99 test.run(chdir = dir) # no arguments, use the Default
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')))
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")
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")
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")
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")
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')
128 test.run(chdir = 'six', status = 2, stderr =
129 "scons: *** No targets specified and no Default() targets found. Stop.\n")
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)
139 test.run(chdir = 'seven', status = 2, stderr =
140 "scons: *** No targets specified and no Default() targets found. Stop.\n")
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)
150 test.run(chdir = 'eight') # no arguments, use the Default
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")
158 test.subdir('nine', ['nine', 'sub1'])
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')
167 test.write(['nine', 'xxx.in'], "xxx.in\n")
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')
176 test.write(['nine', 'sub1', 'xxx.in'], "sub1/xxx.in\n")
178 test.run(chdir = 'nine') # no arguments, use the Default
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")
185 test.subdir('ten', ['ten', 'sub2'])
187 test.write(['ten', 'SConstruct'], """\
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')
195 test.write(['ten', 'xxx.in'], "xxx.in\n")
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')
203 test.write(['ten', 'sub2', 'xxx.in'], "sub2/xxx.in\n")
205 test.run(chdir = 'ten') # no arguments, use the Default
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")
211 test.subdir('eleven')
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')
221 test.write(os.path.join('eleven', 'foo.in'), "eleven/foo.in\n");
223 test.write(os.path.join('eleven', 'bar.in'), "eleven/bar.in\n");
225 test.run(chdir = 'eleven') # no arguments, use the Default
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')))
236 # indent-tabs-mode:nil
238 # vim: set expandtab tabstop=4 shiftwidth=4: