[ci skip] Add note that this change may break SetOption() + ninja usage with fix
[scons.git] / test / Delete.py
blobfc4ab4fd3c3d55cc3e879ebf493d899c9b5038a2
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 Verify that the Delete() Action works.
29 """
31 import sys
32 import os.path
34 import TestSCons
36 test = TestSCons.TestSCons()
38 test.write('SConstruct', """
39 Execute(Delete('f1'))
40 Execute(Delete('d2'))
41 Execute(Delete('symlinks/filelink'))
42 Execute(Delete('symlinks/brokenlink'))
43 Execute(Delete('symlinks/dirlink'))
45 def cat(env, source, target):
46 target = str(target[0])
47 with open(target, "wb") as ofp:
48 for src in source:
49 with open(str(src), "rb") as ifp:
50 ofp.write(ifp.read())
51 Cat = Action(cat)
52 env = Environment()
53 env.Command('f3.out', 'f3.in', [Cat, Delete("f4"), Delete("d5")])
54 env = Environment(FILE='f6', DIR='d7')
55 env.Command('f8.out', 'f8.in', [Delete("$FILE"), Delete("$DIR"), Cat])
56 env.Command('f9.out', 'f9.in', [Cat,
57 Delete("Delete-$SOURCE"),
58 Delete("$TARGET-Delete")])
60 env.Command('f10-nonexistent.out', 'f10.in',
61 [Delete("$TARGET"), Cat])
63 env.Command(Dir('d11-nonexistent.out'), 'd11.in',
64 [Delete("$TARGET"), Mkdir("$TARGET")])
66 env.Command('f12-nonexistent.out', 'f12.in',
67 [Delete("$TARGET", must_exist=0), Cat])
69 env.Command(Dir('d13-nonexistent.out'), 'd13.in',
70 [Delete("$TARGET", must_exist=0), Mkdir("$TARGET")])
72 # Make sure Delete works with a list of arguments
73 env = Environment(FILE='f14', DIR='d15')
74 env.Command('f16.out', 'f16.in', [Delete(["$FILE", "$DIR"]), Cat])
75 """)
77 test.write('f1', "f1\n")
78 test.subdir('d2')
79 test.write(['d2', 'file'], "d2/file\n")
80 test.write('f3.in', "f3.in\n")
81 test.write('f4', "f4\n")
82 test.subdir('d5')
83 test.write(['d5', 'file'], "d5/file\n")
84 test.write('f6', "f6\n")
85 test.subdir('d7')
86 test.write(['d7', 'file'], "d7/file\n")
87 test.write('f8.in', "f8.in\n")
88 test.write('f9.in', "f9.in\n")
89 test.write('Delete-f9.in', "Delete-f9.in\n")
90 test.write('f9.out-Delete', "f9.out-Delete\n")
91 test.write('f10.in', "f10.in\n")
92 test.subdir('d11.in')
93 test.write('f12.in', "f12.in\n")
94 test.subdir('d13.in')
95 test.write('f14', "f14\n")
96 test.subdir('d15')
97 test.write('f16.in', "f16.in\n")
98 test.subdir('symlinks')
99 test.subdir('symlinks/dirtarget')
100 test.write('symlinks/dirtarget/dircontent', 'dircontent content\n')
101 test.write('symlinks/filetarget', 'filetarget content\n')
102 test.symlink('filetarget', 'symlinks/filelink')
103 test.symlink('dirtarget', 'symlinks/dirlink')
104 test.symlink('brokentarget', 'symlinks/brokenlink')
106 expect = test.wrap_stdout(read_str = """\
107 Delete("f1")
108 Delete("d2")
109 Delete("symlinks/filelink")
110 Delete("symlinks/brokenlink")
111 Delete("symlinks/dirlink")
112 """,
113 build_str = """\
114 Delete("d11-nonexistent.out")
115 Mkdir("d11-nonexistent.out")
116 Delete("d13-nonexistent.out")
117 Mkdir("d13-nonexistent.out")
118 Delete("f10-nonexistent.out")
119 cat(["f10-nonexistent.out"], ["f10.in"])
120 Delete("f12-nonexistent.out")
121 cat(["f12-nonexistent.out"], ["f12.in"])
122 Delete(["f14", "d15"])
123 cat(["f16.out"], ["f16.in"])
124 cat(["f3.out"], ["f3.in"])
125 Delete("f4")
126 Delete("d5")
127 Delete("f6")
128 Delete("d7")
129 cat(["f8.out"], ["f8.in"])
130 cat(["f9.out"], ["f9.in"])
131 Delete("Delete-f9.in")
132 Delete("f9.out-Delete")
133 """)
134 test.run(options = '-n', arguments = '.', stdout = expect)
136 test.must_exist('f1')
137 test.must_exist('d2')
138 test.must_exist(os.path.join('d2', 'file'))
139 test.must_not_exist('f3.out')
140 test.must_exist('f4')
141 test.must_exist('d5')
142 test.must_exist(os.path.join('d5', 'file'))
143 test.must_exist('f6')
144 test.must_exist('d7')
145 test.must_exist(os.path.join('d7', 'file'))
146 test.must_not_exist('f8.out')
147 test.must_not_exist('f9.out')
148 test.must_exist('Delete-f9.in')
149 test.must_exist('f9.out-Delete')
150 test.must_exist('f14')
151 test.must_exist('d15')
152 test.must_not_exist('f16.out')
153 if sys.platform != 'win32':
154 test.must_exist('symlinks')
155 test.must_exist('symlinks/dirtarget')
156 test.must_exist('symlinks/dirtarget/dircontent')
157 test.must_exist('symlinks/filetarget')
158 test.must_exist('symlinks/filelink')
159 test.must_exist('symlinks/brokenlink')
160 test.must_exist('symlinks/dirlink')
162 test.run()
164 test.must_not_exist('f1')
165 test.must_not_exist('d2')
166 test.must_not_exist(os.path.join('d2', 'file'))
167 test.must_match('f3.out', "f3.in\n")
168 test.must_not_exist('f4')
169 test.must_not_exist('d5')
170 test.must_not_exist(os.path.join('d5', 'file'))
171 test.must_not_exist('f6')
172 test.must_not_exist('d7')
173 test.must_not_exist(os.path.join('d7', 'file'))
174 test.must_match('f8.out', "f8.in\n")
175 test.must_match('f9.out', "f9.in\n")
176 test.must_not_exist('Delete-f9.in')
177 test.must_not_exist('f9.out-Delete')
178 test.must_exist('f10-nonexistent.out')
179 test.must_exist('d11-nonexistent.out')
180 test.must_exist('f12-nonexistent.out')
181 test.must_exist('d13-nonexistent.out')
182 test.must_not_exist('f14')
183 test.must_not_exist('d15')
184 test.must_match('f16.out', "f16.in\n")
185 if sys.platform != 'win32':
186 test.must_exist('symlinks')
187 test.must_exist('symlinks/dirtarget')
188 test.must_exist('symlinks/dirtarget/dircontent')
189 test.must_exist('symlinks/filetarget')
190 test.must_not_exist('symlinks/filelink')
191 test.must_not_exist('symlinks/brokenlink')
192 test.must_not_exist('symlinks/dirlink')
194 test.write("SConstruct", """\
195 def cat(env, source, target):
196 target = str(target[0])
197 with open(target, "wb") as ifp:
198 for src in source:
199 with open(str(src), "rb") as ofp:
200 ofp.write(ifp.read())
201 Cat = Action(cat)
202 env = Environment()
203 env.Command('f14-nonexistent.out', 'f14.in', [Delete("$TARGET", must_exist=1),
204 Cat])
205 """)
207 test.write('f14.in', "f14.in\n")
209 test.run(status=2, stderr=None)
211 fail_strings = [
212 "No such file or directory",
213 "The system cannot find the file specified",
214 "The system cannot find the path specified",
215 "Das System kann die angegebene Datei nicht finden",
218 test.must_contain_any_line(test.stderr(), fail_strings)
220 test.pass_test()
222 # Local Variables:
223 # tab-width:4
224 # indent-tabs-mode:nil
225 # End:
226 # vim: set expandtab tabstop=4 shiftwidth=4: