Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Delete.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Verify that the Delete() Action works.
29 """
30
31 import os.path
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 test.write('SConstruct', """
38 Execute(Delete('f1'))
39 Execute(Delete('d2'))
40 def cat(env, source, target):
41     target = str(target[0])
42     f = open(target, "wb")
43     for src in source:
44         f.write(open(str(src), "rb").read())
45     f.close()
46 Cat = Action(cat)
47 env = Environment()
48 env.Command('f3.out', 'f3.in', [Cat, Delete("f4"), Delete("d5")])
49 env = Environment(FILE='f6', DIR='d7')
50 env.Command('f8.out', 'f8.in', [Delete("$FILE"), Delete("$DIR"), Cat])
51 env.Command('f9.out', 'f9.in', [Cat,
52                                 Delete("Delete-$SOURCE"),
53                                 Delete("$TARGET-Delete")])
54
55 env.Command('f10-nonexistent.out', 'f10.in',
56             [Delete("$TARGET"), Cat])
57
58 env.Command(Dir('d11-nonexistent.out'), 'd11.in',
59             [Delete("$TARGET"), Mkdir("$TARGET")])
60
61 env.Command('f12-nonexistent.out', 'f12.in',
62             [Delete("$TARGET", must_exist=0), Cat])
63
64 env.Command(Dir('d13-nonexistent.out'), 'd13.in',
65             [Delete("$TARGET", must_exist=0), Mkdir("$TARGET")])
66
67 # Make sure Delete works with a list of arguments
68 env = Environment(FILE='f14', DIR='d15')
69 env.Command('f16.out', 'f16.in', [Delete(["$FILE", "$DIR"]), Cat])
70 """)
71
72 test.write('f1', "f1\n")
73 test.subdir('d2')
74 test.write(['d2', 'file'], "d2/file\n")
75 test.write('f3.in', "f3.in\n")
76 test.write('f4', "f4\n")
77 test.subdir('d5')
78 test.write(['d5', 'file'], "d5/file\n")
79 test.write('f6', "f6\n")
80 test.subdir('d7')
81 test.write(['d7', 'file'], "d7/file\n")
82 test.write('f8.in', "f8.in\n")
83 test.write('f9.in', "f9.in\n")
84 test.write('Delete-f9.in', "Delete-f9.in\n")
85 test.write('f9.out-Delete', "f9.out-Delete\n")
86 test.write('f10.in', "f10.in\n")
87 test.subdir('d11.in')
88 test.write('f12.in', "f12.in\n")
89 test.subdir('d13.in')
90 test.write('f14', "f14\n")
91 test.subdir('d15')
92 test.write('f16.in', "f16.in\n")
93
94 expect = test.wrap_stdout(read_str = """\
95 Delete("f1")
96 Delete("d2")
97 """,
98                           build_str = """\
99 Delete("d11-nonexistent.out")
100 Mkdir("d11-nonexistent.out")
101 Delete("d13-nonexistent.out")
102 Mkdir("d13-nonexistent.out")
103 Delete("f10-nonexistent.out")
104 cat(["f10-nonexistent.out"], ["f10.in"])
105 Delete("f12-nonexistent.out")
106 cat(["f12-nonexistent.out"], ["f12.in"])
107 Delete(["f14", "d15"])
108 cat(["f16.out"], ["f16.in"])
109 cat(["f3.out"], ["f3.in"])
110 Delete("f4")
111 Delete("d5")
112 Delete("f6")
113 Delete("d7")
114 cat(["f8.out"], ["f8.in"])
115 cat(["f9.out"], ["f9.in"])
116 Delete("Delete-f9.in")
117 Delete("f9.out-Delete")
118 """)
119 test.run(options = '-n', arguments = '.', stdout = expect)
120
121 test.must_exist('f1')
122 test.must_exist('d2')
123 test.must_exist(os.path.join('d2', 'file'))
124 test.must_not_exist('f3.out')
125 test.must_exist('f4')
126 test.must_exist('d5')
127 test.must_exist(os.path.join('d5', 'file'))
128 test.must_exist('f6')
129 test.must_exist('d7')
130 test.must_exist(os.path.join('d7', 'file'))
131 test.must_not_exist('f8.out')
132 test.must_not_exist('f9.out')
133 test.must_exist('Delete-f9.in')
134 test.must_exist('f9.out-Delete')
135 test.must_exist('f14')
136 test.must_exist('d15')
137 test.must_not_exist('f16.out')
138
139 test.run()
140
141 test.must_not_exist('f1')
142 test.must_not_exist('d2')
143 test.must_not_exist(os.path.join('d2', 'file'))
144 test.must_match('f3.out', "f3.in\n")
145 test.must_not_exist('f4')
146 test.must_not_exist('d5')
147 test.must_not_exist(os.path.join('d5', 'file'))
148 test.must_not_exist('f6')
149 test.must_not_exist('d7')
150 test.must_not_exist(os.path.join('d7', 'file'))
151 test.must_match('f8.out', "f8.in\n")
152 test.must_match('f9.out', "f9.in\n")
153 test.must_not_exist('Delete-f9.in')
154 test.must_not_exist('f9.out-Delete')
155 test.must_exist('f10-nonexistent.out')
156 test.must_exist('d11-nonexistent.out')
157 test.must_exist('f12-nonexistent.out')
158 test.must_exist('d13-nonexistent.out')
159 test.must_not_exist('f14')
160 test.must_not_exist('d15')
161 test.must_match('f16.out', "f16.in\n")
162
163 test.write("SConstruct", """\
164 def cat(env, source, target):
165     target = str(target[0])
166     f = open(target, "wb")
167     for src in source:
168         f.write(open(str(src), "rb").read())
169     f.close()
170 Cat = Action(cat)
171 env = Environment()
172 env.Command('f14-nonexistent.out', 'f14.in', [Delete("$TARGET", must_exist=1),
173                                               Cat])
174 """)
175
176 test.write('f14.in', "f14.in\n")
177
178 test.run(status=2, stderr=None)
179
180 fail_strings = [
181     "No such file or directory",
182     "The system cannot find the file specified",
183     "The system cannot find the path specified",
184 ]
185
186 test.must_contain_any_line(test.stderr(), fail_strings)
187
188 test.pass_test()
189
190 # Local Variables:
191 # tab-width:4
192 # indent-tabs-mode:nil
193 # End:
194 # vim: set expandtab tabstop=4 shiftwidth=4: