5 // Jonathan Chambers (joncham@gmail.com)
7 // (C) 2008 Jonathan Chambers
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections;
31 using Microsoft.Build.BuildEngine;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Tasks;
34 using Microsoft.Build.Utilities;
35 using NUnit.Framework;
37 namespace MonoTests.Microsoft.Build.Tasks {
40 public class DeleteTest {
44 public void CreateDir ()
46 path = Path.Combine (Path.Combine ("Test", "resources"), "Delete");
47 Directory.CreateDirectory (path);
51 public void RemoveDirectories ()
53 Directory.Delete (path, true);
57 public void TestDelete1 ()
61 string file_path = Path.Combine(path, "delete.txt");
63 using (File.CreateText (file_path)) { }
65 string documentString = @"
66 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
68 <Delete Files='" + file_path + @"'/>
73 engine = new Engine (Consts.BinPath);
74 project = engine.CreateNewProject ();
75 project.LoadXml (documentString);
77 Assert.IsTrue (project.Build ("1"), "A1");
78 Assert.IsTrue (!File.Exists (file_path), "A2");
82 public void TestDelete2 ()
86 string file_path = Path.Combine (path, "delete.txt");
87 string file_path2 = Path.Combine (path, "delete2.txt");
89 using (File.CreateText (file_path)) { }
90 using (File.CreateText (file_path2)) { }
92 string documentString = @"
93 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
95 <Delete Files='" + file_path + ";" + file_path2 + @"'/>
100 engine = new Engine (Consts.BinPath);
101 project = engine.CreateNewProject ();
102 project.LoadXml (documentString);
104 Assert.IsTrue (project.Build ("1"), "A1");
105 Assert.IsTrue (!File.Exists (file_path), "A2");
106 Assert.IsTrue (!File.Exists (file_path), "A3");
110 public void TestDelete3 ()
114 string file_path = Path.Combine (path, "delete.txt");
116 using (File.CreateText (file_path)) { }
118 string documentString = @"
119 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
121 <FileToDelete>" + file_path + @"</FileToDelete>
124 <Delete Files='$(FileToDelete)'/>
129 engine = new Engine (Consts.BinPath);
130 project = engine.CreateNewProject ();
131 project.LoadXml (documentString);
133 Assert.IsTrue (project.Build ("1"), "A1");
134 Assert.IsTrue (!File.Exists (file_path), "A2");
138 public void TestDelete4 ()
142 string file_path = Path.Combine (path, "delete.txt");
143 string file_path2 = Path.Combine (path, "delete2.txt");
145 using (File.CreateText (file_path)) { }
146 using (File.CreateText (file_path2)) { }
148 string documentString = @"
149 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
151 <FileToDelete>" + file_path + @"</FileToDelete>
152 <FileToDelete2>" + file_path2 + @"</FileToDelete2>
155 <Delete Files='$(FileToDelete);$(FileToDelete2)'/>
160 engine = new Engine (Consts.BinPath);
161 project = engine.CreateNewProject ();
162 project.LoadXml (documentString);
164 Assert.IsTrue (project.Build ("1"), "A1");
165 Assert.IsTrue (!File.Exists (file_path), "A2");
166 Assert.IsTrue (!File.Exists (file_path2), "A3");
170 public void TestDelete5 ()
174 string file_path = Path.Combine (path, "delete.txt");
176 using (File.CreateText (file_path)) { }
178 string documentString = @"
179 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
181 <File Include='" + file_path + @"' />
184 <Delete Files='@(File)'/>
189 engine = new Engine (Consts.BinPath);
190 project = engine.CreateNewProject ();
191 project.LoadXml (documentString);
193 Assert.IsTrue (project.Build ("1"), "A1");
194 Assert.IsTrue (!File.Exists (file_path), "A2");
199 public void TestDelete6 ()
203 string file_path = Path.Combine (path, "delete.txt");
204 string file_path2 = Path.Combine (path, "delete2.txt");
206 using (File.CreateText (file_path)) { }
207 using (File.CreateText (file_path2)) { }
209 string documentString = @"
210 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
212 <File Include='" + file_path + @"' />
213 <File Include='" + file_path2 + @"' />
216 <Delete Files='@(File)'/>
221 engine = new Engine (Consts.BinPath);
222 project = engine.CreateNewProject ();
223 project.LoadXml (documentString);
225 Assert.IsTrue (project.Build ("1"), "A1");
226 Assert.IsTrue (!File.Exists (file_path), "A2");
227 Assert.IsTrue (!File.Exists (file_path2), "A3");
231 [Category ("NotWorking")]
232 public void TestDelete7 ()
236 string file_path = Path.Combine (path, "delete.txt");
238 using (File.CreateText (file_path)) { }
240 string documentString = @"
241 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
243 <FolderToDelete>" + path + @"</FolderToDelete>
244 <FileToDelete>delete</FileToDelete>
245 <ExtToDelete>txt</ExtToDelete>
248 <Delete Files='$(FolderToDelete)\$(FileToDelete).$(ExtToDelete)'/>
253 engine = new Engine (Consts.BinPath);
254 project = engine.CreateNewProject ();
255 project.LoadXml (documentString);
257 Assert.IsTrue (project.Build ("1"), "A1");
258 Assert.IsTrue (!File.Exists (file_path), "A2");