[ci skip] remove umerged conflict markers in RELEASE.txt
[scons.git] / test / Clean / basic.py
blobfbff9b1836dbb48ade87ac3e2ac57b2159ac5de3
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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__"
27 """
28 Test various basic uses of the -c (clean) option.
29 """
31 import os
33 import TestSCons
35 _python_ = TestSCons._python_
37 test = TestSCons.TestSCons()
39 test.write('build.py', r"""
40 import sys
41 with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
42 ofp.write(ifp.read())
43 """)
45 test.write('SConstruct', """
46 DefaultEnvironment(tools=[])
47 B = Builder(action = r'%(_python_)s build.py $TARGETS $SOURCES')
48 env = Environment(tools=[], BUILDERS = { 'B' : B })
49 env.B(target = 'foo1.out', source = 'foo1.in')
50 env.B(target = 'foo2.out', source = 'foo2.xxx')
51 env.B(target = 'foo2.xxx', source = 'foo2.in')
52 env.B(target = 'foo3.out', source = 'foo3.in')
53 env.B(target = 'foo4.out', source = 'foo4.in')
54 env.NoClean('foo4.out')
55 import os
56 import sys
57 if hasattr(os, 'symlink') and sys.platform !='win32':
58 def symlink1(env, target, source):
59 # symlink to a file that exists
60 os.symlink(str(source[0]), str(target[0]))
61 env.Command(target = 'symlink1', source = 'foo1.in', action = symlink1)
62 def symlink2(env, target, source):
63 # force symlink to a file that doesn't exist
64 os.symlink('does_not_exist', str(target[0]))
65 env.Command(target = 'symlink2', source = 'foo1.in', action = symlink2)
66 # Test handling of Builder calls that have multiple targets.
67 env.Command(['touch1.out', 'touch2.out'],
68 [],
69 [Touch('${TARGETS[0]}'), Touch('${TARGETS[1]}')])
70 """ % locals())
72 test.write('foo1.in', "foo1.in\n")
74 test.write('foo2.in', "foo2.in\n")
76 test.write('foo3.in', "foo3.in\n")
78 test.write('foo4.in', "foo4.in\n")
80 test.run(arguments = 'foo1.out foo2.out foo3.out foo4.out')
82 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
83 test.must_match(test.workpath('foo2.xxx'), "foo2.in\n")
84 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
85 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
86 test.must_match(test.workpath('foo4.out'), "foo4.in\n")
88 test.run(arguments = '-c foo1.out',
89 stdout = test.wrap_stdout("Removed foo1.out\n", cleaning=1))
91 test.must_not_exist(test.workpath('foo1.out'))
92 test.must_exist(test.workpath('foo2.xxx'))
93 test.must_exist(test.workpath('foo2.out'))
94 test.must_exist(test.workpath('foo3.out'))
95 test.must_exist(test.workpath('foo4.out'))
97 test.run(arguments = '--clean foo2.out foo2.xxx',
98 stdout = test.wrap_stdout("Removed foo2.xxx\nRemoved foo2.out\n",
99 cleaning=1))
101 test.must_not_exist(test.workpath('foo1.out'))
102 test.must_not_exist(test.workpath('foo2.xxx'))
103 test.must_not_exist(test.workpath('foo2.out'))
104 test.must_exist(test.workpath('foo3.out'))
105 test.must_exist(test.workpath('foo4.out'))
107 test.run(arguments = '--remove foo3.out',
108 stdout = test.wrap_stdout("Removed foo3.out\n", cleaning=1))
110 test.must_not_exist(test.workpath('foo1.out'))
111 test.must_not_exist(test.workpath('foo2.xxx'))
112 test.must_not_exist(test.workpath('foo2.out'))
113 test.must_not_exist(test.workpath('foo3.out'))
114 test.must_exist(test.workpath('foo4.out'))
116 test.run(arguments = '.')
118 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
119 test.must_match(test.workpath('foo2.xxx'), "foo2.in\n")
120 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
121 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
122 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
123 test.must_match(test.workpath('foo4.out'), "foo4.in\n")
124 test.must_exist(test.workpath('touch1.out'))
125 test.must_exist(test.workpath('touch2.out'))
127 if test.platform_has_symlink():
128 test.fail_test(not os.path.islink(test.workpath('symlink1')))
129 test.fail_test(not os.path.islink(test.workpath('symlink2')))
131 test.run(arguments = '-c foo2.xxx',
132 stdout = test.wrap_stdout("Removed foo2.xxx\n", cleaning=1))
134 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
135 test.must_not_exist(test.workpath('foo2.xxx'))
136 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
137 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
138 test.must_match(test.workpath('foo4.out'), "foo4.in\n")
139 test.must_exist(test.workpath('touch1.out'))
140 test.must_exist(test.workpath('touch2.out'))
142 test.run(arguments = '-c .')
144 test.must_not_exist(test.workpath('foo1.out'))
145 test.must_not_exist(test.workpath('foo2.out'))
146 test.must_not_exist(test.workpath('foo3.out'))
147 test.must_exist(test.workpath('foo4.out'))
148 test.must_not_exist(test.workpath('touch1.out'))
149 test.must_not_exist(test.workpath('touch2.out'))
151 if test.platform_has_symlink():
152 test.fail_test(os.path.islink(test.workpath('symlink1')))
153 test.fail_test(os.path.islink(test.workpath('symlink2')))
155 args = 'foo1.out foo2.out foo3.out touch1.out'
157 expect = test.wrap_stdout("""\
158 Removed foo1.out
159 Removed foo2.xxx
160 Removed foo2.out
161 Removed foo3.out
162 Removed touch1.out
163 Removed touch2.out
164 """, cleaning=1)
166 test.run(arguments = args)
168 test.run(arguments = '-c -n ' + args, stdout = expect)
170 test.run(arguments = '-n -c ' + args, stdout = expect)
172 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
173 test.must_match(test.workpath('foo2.xxx'), "foo2.in\n")
174 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
175 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
176 test.must_match(test.workpath('foo4.out'), "foo4.in\n")
177 test.must_exist(test.workpath('touch1.out'))
178 test.must_exist(test.workpath('touch2.out'))
180 test.pass_test()
182 # Local Variables:
183 # tab-width:4
184 # indent-tabs-mode:nil
185 # End:
186 # vim: set expandtab tabstop=4 shiftwidth=4: