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 that the Delete() Action works.
36 test = TestSCons.TestSCons()
38 test.write('SConstruct', """
41 def cat(env, source, target):
42 target = str(target[0])
43 source = map(str, source)
44 f = open(target, "wb")
46 f.write(open(src, "rb").read())
50 env.Command('f3.out', 'f3.in', [Cat, Delete("f4"), Delete("d5")])
51 env = Environment(FILE='f6', DIR='d7')
52 env.Command('f8.out', 'f8.in', [Delete("$FILE"), Delete("$DIR"), Cat])
53 env.Command('f9.out', 'f9.in', [Cat,
54 Delete("Delete-$SOURCE"),
55 Delete("$TARGET-Delete")])
57 env.Command('f10-nonexistent.out', 'f10.in',
58 [Delete("$TARGET"), Cat])
60 env.Command(Dir('d11-nonexistent.out'), 'd11.in',
61 [Delete("$TARGET"), Mkdir("$TARGET")])
63 env.Command('f12-nonexistent.out', 'f12.in',
64 [Delete("$TARGET", must_exist=0), Cat])
66 env.Command(Dir('d13-nonexistent.out'), 'd13.in',
67 [Delete("$TARGET", must_exist=0), Mkdir("$TARGET")])
69 # Make sure Delete works with a list of arguments
70 env = Environment(FILE='f14', DIR='d15')
71 env.Command('f16.out', 'f16.in', [Delete(["$FILE", "$DIR"]), Cat])
74 test.write('f1', "f1\n")
76 test.write(['d2', 'file'], "d2/file\n")
77 test.write('f3.in', "f3.in\n")
78 test.write('f4', "f4\n")
80 test.write(['d5', 'file'], "d5/file\n")
81 test.write('f6', "f6\n")
83 test.write(['d7', 'file'], "d7/file\n")
84 test.write('f8.in', "f8.in\n")
85 test.write('f9.in', "f9.in\n")
86 test.write('Delete-f9.in', "Delete-f9.in\n")
87 test.write('f9.out-Delete', "f9.out-Delete\n")
88 test.write('f10.in', "f10.in\n")
90 test.write('f12.in', "f12.in\n")
92 test.write('f14', "f14\n")
94 test.write('f16.in', "f16.in\n")
96 expect = test.wrap_stdout(read_str = """\
101 Delete("d11-nonexistent.out")
102 Mkdir("d11-nonexistent.out")
103 Delete("d13-nonexistent.out")
104 Mkdir("d13-nonexistent.out")
105 Delete("f10-nonexistent.out")
106 cat(["f10-nonexistent.out"], ["f10.in"])
107 Delete("f12-nonexistent.out")
108 cat(["f12-nonexistent.out"], ["f12.in"])
109 Delete(["f14", "d15"])
110 cat(["f16.out"], ["f16.in"])
111 cat(["f3.out"], ["f3.in"])
116 cat(["f8.out"], ["f8.in"])
117 cat(["f9.out"], ["f9.in"])
118 Delete("Delete-f9.in")
119 Delete("f9.out-Delete")
121 test.run(options = '-n', arguments = '.', stdout = expect)
123 test.must_exist('f1')
124 test.must_exist('d2')
125 test.must_exist(os.path.join('d2', 'file'))
126 test.must_not_exist('f3.out')
127 test.must_exist('f4')
128 test.must_exist('d5')
129 test.must_exist(os.path.join('d5', 'file'))
130 test.must_exist('f6')
131 test.must_exist('d7')
132 test.must_exist(os.path.join('d7', 'file'))
133 test.must_not_exist('f8.out')
134 test.must_not_exist('f9.out')
135 test.must_exist('Delete-f9.in')
136 test.must_exist('f9.out-Delete')
137 test.must_exist('f14')
138 test.must_exist('d15')
139 test.must_not_exist('f16.out')
143 test.must_not_exist('f1')
144 test.must_not_exist('d2')
145 test.must_not_exist(os.path.join('d2', 'file'))
146 test.must_match('f3.out', "f3.in\n")
147 test.must_not_exist('f4')
148 test.must_not_exist('d5')
149 test.must_not_exist(os.path.join('d5', 'file'))
150 test.must_not_exist('f6')
151 test.must_not_exist('d7')
152 test.must_not_exist(os.path.join('d7', 'file'))
153 test.must_match('f8.out', "f8.in\n")
154 test.must_match('f9.out', "f9.in\n")
155 test.must_not_exist('Delete-f9.in')
156 test.must_not_exist('f9.out-Delete')
157 test.must_exist('f10-nonexistent.out')
158 test.must_exist('d11-nonexistent.out')
159 test.must_exist('f12-nonexistent.out')
160 test.must_exist('d13-nonexistent.out')
161 test.must_not_exist('f14')
162 test.must_not_exist('d15')
163 test.must_match('f16.out', "f16.in\n")
165 test.write("SConstruct", """\
166 def cat(env, source, target):
167 target = str(target[0])
168 source = map(str, source)
169 f = open(target, "wb")
171 f.write(open(src, "rb").read())
175 env.Command('f14-nonexistent.out', 'f14.in', [Delete("$TARGET", must_exist=1),
179 test.write('f14.in', "f14.in\n")
181 test.run(status=2, stderr=None)
183 stderr = test.stderr()
184 test.fail_test(string.find(stderr, "No such file or directory") == -1 and
185 string.find(stderr, "The system cannot find the path specified") == -1)