[ci skip] update generated files
[scons.git] / test / Climb / option--U.py
blob8c34462b45011ec20ecfe6226c7c06838e5ce26b
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 sys
28 import TestSCons
30 test = TestSCons.TestSCons()
32 _python_ = TestSCons._python_
34 test.subdir('sub1', 'sub2', 'sub3')
36 test.write('build.py', r"""
37 import sys
38 with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
39 ofp.write(ifp.read())
40 """)
42 test.write('SConstruct', r"""
43 DefaultEnvironment(tools=[])
44 import SCons.Defaults
45 env = Environment(tools=[])
46 env['BUILDERS']['B'] = Builder(action=r'%(_python_)s build.py $TARGET $SOURCES', multi=1)
47 Default(env.B(target = 'sub1/foo.out', source = 'sub1/foo.in'))
48 Export('env')
49 SConscript('sub2/SConscript')
50 Default(env.B(target = 'sub3/baz.out', source = 'sub3/baz.in'))
51 VariantDir('sub2b', 'sub2')
52 SConscript('sub2b/SConscript')
53 Default(env.B(target = 'sub2/xxx.out', source = 'xxx.in'))
54 SConscript('SConscript')
55 """ % locals())
57 test.write(['sub2', 'SConscript'], """
58 Import('env')
59 bar = env.B(target = 'bar.out', source = 'bar.in')
60 Default(bar)
61 env.Alias('bar', bar)
62 Default(env.B(target = '../bar.out', source = 'bar.in'))
63 """)
66 test.write(['sub1', 'foo.in'], "sub1/foo.in\n")
67 test.write(['sub2', 'bar.in'], "sub2/bar.in\n")
68 test.write(['sub3', 'baz.in'], "sub3/baz.in\n")
69 test.write('xxx.in', "xxx.in\n")
71 test.write('SConscript', """assert GetLaunchDir() == r'%s'\n"""%test.workpath('sub1'))
72 test.run(arguments = '-U foo.out', chdir = 'sub1')
74 test.must_exist(test.workpath('sub1', 'foo.out'))
75 test.must_not_exist(test.workpath('sub2', 'bar.out'))
76 test.must_not_exist(test.workpath('sub2b', 'bar.out'))
77 test.must_not_exist(test.workpath('sub3', 'baz.out'))
78 test.must_not_exist(test.workpath('bar.out'))
79 test.must_not_exist(test.workpath('sub2/xxx.out'))
81 test.unlink(['sub1', 'foo.out'])
83 test.write('SConscript', """\
84 env = Environment(tools=[], )
85 assert env.GetLaunchDir() == r'%s'
86 """%test.workpath('sub1'))
87 test.run(arguments = '-U',
88 chdir = 'sub1',
89 stderr = "scons: *** No targets specified and no Default() targets found. Stop.\n",
90 status = 2)
91 test.must_not_exist(test.workpath('sub1', 'foo.out'))
92 test.must_not_exist(test.workpath('sub2', 'bar.out'))
93 test.must_not_exist(test.workpath('sub2b', 'bar.out'))
94 test.must_not_exist(test.workpath('sub3', 'baz.out'))
95 test.must_not_exist(test.workpath('bar.out'))
96 test.must_not_exist(test.workpath('sub2/xxx.out'))
99 if sys.platform == 'win32':
100 sub2 = 'SUB2'
101 else:
102 sub2 = 'sub2'
103 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath(sub2))
104 test.run(chdir = sub2, arguments = '-U')
105 test.must_not_exist(test.workpath('sub1', 'foo.out'))
106 test.must_exist(test.workpath('sub2', 'bar.out'))
107 test.must_exist(test.workpath('sub2b', 'bar.out'))
108 test.must_not_exist(test.workpath('sub3', 'baz.out'))
109 test.must_exist(test.workpath('bar.out'))
110 test.must_not_exist(test.workpath('sub2/xxx.out'))
112 test.unlink(['sub2', 'bar.out'])
113 test.unlink(['sub2b', 'bar.out'])
114 test.unlink('bar.out')
116 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath())
117 test.run(arguments='-U')
118 test.must_exist(test.workpath('sub1', 'foo.out'))
119 test.must_not_exist(test.workpath('sub2', 'bar.out'))
120 test.must_not_exist(test.workpath('sub2b', 'bar.out'))
121 test.must_exist(test.workpath('sub3', 'baz.out'))
122 test.must_not_exist(test.workpath('bar.out'))
123 test.must_exist(test.workpath('sub2/xxx.out'))
125 test.unlink(['sub1', 'foo.out'])
126 test.unlink(['sub3', 'baz.out'])
127 test.unlink(['sub2', 'xxx.out'])
129 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub3'))
130 test.run(chdir = 'sub3', arguments='-U bar')
131 test.must_not_exist(test.workpath('sub1', 'foo.out'))
132 test.must_exist(test.workpath('sub2', 'bar.out'))
133 test.must_exist(test.workpath('sub2b', 'bar.out'))
134 test.must_not_exist(test.workpath('sub3', 'baz.out'))
135 test.must_not_exist(test.workpath('bar.out'))
136 test.must_not_exist(test.workpath('sub2/xxx.out'))
138 test.pass_test()
140 # Local Variables:
141 # tab-width:4
142 # indent-tabs-mode:nil
143 # End:
144 # vim: set expandtab tabstop=4 shiftwidth=4: