Merge pull request #1232 from akoeplinger/fix-test
[mono.git] / mcs / class / Microsoft.Build.Tasks / Test / Microsoft.Build.Tasks / DeleteTest.cs
1 //
2 // DeleteTest.cs
3 //  
4 // Author:
5 //   Jonathan Chambers (joncham@gmail.com)
6 //
7 // (C) 2008 Jonathan Chambers
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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.
27
28 using System;
29 using System.Collections;
30 using System.IO;
31 using Microsoft.Build.BuildEngine;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Tasks;
34 using Microsoft.Build.Utilities;
35 using NUnit.Framework;
36
37 namespace MonoTests.Microsoft.Build.Tasks {
38
39         [TestFixture]
40         public class DeleteTest {
41                 string path;
42
43                 [SetUp]
44                 public void CreateDir ()
45                 {
46                         path = Path.Combine (Path.Combine ("Test", "resources"), "Delete");
47                         Directory.CreateDirectory (path);
48                 }
49
50                 [TearDown]
51                 public void RemoveDirectories ()
52                 {
53                         Directory.Delete (path, true);
54                 }
55
56                 [Test]
57                 public void TestDelete1 ()
58                 {
59                         Engine engine;
60                         Project project;
61                         string file_path = Path.Combine(path, "delete.txt");
62
63                         using (File.CreateText (file_path)) { }
64
65                         string documentString = @"
66                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
67                                         <Target Name='1'>
68                                                 <Delete Files='" + file_path + @"'/>
69                                         </Target>
70                                 </Project>
71                         ";
72
73                         engine = new Engine (Consts.BinPath);
74                         project = engine.CreateNewProject ();
75                         project.LoadXml (documentString);
76
77                         Assert.IsTrue (project.Build ("1"), "A1");
78                         Assert.IsTrue (!File.Exists (file_path), "A2");
79                 }
80
81                 [Test]
82                 public void TestDelete2 ()
83                 {
84                         Engine engine;
85                         Project project;
86                         string file_path = Path.Combine (path, "delete.txt");
87                         string file_path2 = Path.Combine (path, "delete2.txt");
88
89                         using (File.CreateText (file_path)) { }
90                         using (File.CreateText (file_path2)) { }
91
92                         string documentString = @"
93                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
94                                         <Target Name='1'>
95                                                 <Delete Files='" + file_path + ";" + file_path2 + @"'/>
96                                         </Target>
97                                 </Project>
98                         ";
99
100                         engine = new Engine (Consts.BinPath);
101                         project = engine.CreateNewProject ();
102                         project.LoadXml (documentString);
103
104                         Assert.IsTrue (project.Build ("1"), "A1");
105                         Assert.IsTrue (!File.Exists (file_path), "A2");
106                         Assert.IsTrue (!File.Exists (file_path), "A3");
107                 }
108
109                 [Test]
110                 public void TestDelete3 ()
111                 {
112                         Engine engine;
113                         Project project;
114                         string file_path = Path.Combine (path, "delete.txt");
115
116                         using (File.CreateText (file_path)) { }
117
118                         string documentString = @"
119                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
120                                         <PropertyGroup>
121                                                 <FileToDelete>" + file_path + @"</FileToDelete>
122                                         </PropertyGroup>
123                                         <Target Name='1'>
124                                                 <Delete Files='$(FileToDelete)'/>
125                                         </Target>
126                                 </Project>
127                         ";
128
129                         engine = new Engine (Consts.BinPath);
130                         project = engine.CreateNewProject ();
131                         project.LoadXml (documentString);
132
133                         Assert.IsTrue (project.Build ("1"), "A1");
134                         Assert.IsTrue (!File.Exists (file_path), "A2");
135                 }
136
137                 [Test]
138                 public void TestDelete4 ()
139                 {
140                         Engine engine;
141                         Project project;
142                         string file_path = Path.Combine (path, "delete.txt");
143                         string file_path2 = Path.Combine (path, "delete2.txt");
144
145                         using (File.CreateText (file_path)) { }
146                         using (File.CreateText (file_path2)) { }
147
148                         string documentString = @"
149                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
150                                         <PropertyGroup>
151                                                 <FileToDelete>" + file_path + @"</FileToDelete>
152                                                 <FileToDelete2>" + file_path2 + @"</FileToDelete2>
153                                         </PropertyGroup>
154                                         <Target Name='1'>
155                                                 <Delete Files='$(FileToDelete);$(FileToDelete2)'/>
156                                         </Target>
157                                 </Project>
158                         ";
159
160                         engine = new Engine (Consts.BinPath);
161                         project = engine.CreateNewProject ();
162                         project.LoadXml (documentString);
163
164                         Assert.IsTrue (project.Build ("1"), "A1");
165                         Assert.IsTrue (!File.Exists (file_path), "A2");
166                         Assert.IsTrue (!File.Exists (file_path2), "A3");
167                 }
168
169                 [Test]
170                 public void TestDelete5 ()
171                 {
172                         Engine engine;
173                         Project project;
174                         string file_path = Path.Combine (path, "delete.txt");
175
176                         using (File.CreateText (file_path)) { }
177
178                         string documentString = @"
179                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
180                                         <ItemGroup>
181                                                 <File Include='" + file_path + @"' />
182                                         </ItemGroup>
183                                         <Target Name='1'>
184                                                 <Delete Files='@(File)'/>
185                                         </Target>
186                                 </Project>
187                         ";
188
189                         engine = new Engine (Consts.BinPath);
190                         project = engine.CreateNewProject ();
191                         project.LoadXml (documentString);
192
193                         Assert.IsTrue (project.Build ("1"), "A1");
194                         Assert.IsTrue (!File.Exists (file_path), "A2");
195                 }
196
197
198                 [Test]
199                 public void TestDelete6 ()
200                 {
201                         Engine engine;
202                         Project project;
203                         string file_path = Path.Combine (path, "delete.txt");
204                         string file_path2 = Path.Combine (path, "delete2.txt");
205
206                         using (File.CreateText (file_path)) { }
207                         using (File.CreateText (file_path2)) { }
208
209                         string documentString = @"
210                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
211                                         <ItemGroup>
212                                                 <File Include='" + file_path + @"' />
213                                                 <File Include='" + file_path2 + @"' />
214                                         </ItemGroup>
215                                         <Target Name='1'>
216                                                 <Delete Files='@(File)'/>
217                                         </Target>
218                                 </Project>
219                         ";
220
221                         engine = new Engine (Consts.BinPath);
222                         project = engine.CreateNewProject ();
223                         project.LoadXml (documentString);
224
225                         Assert.IsTrue (project.Build ("1"), "A1");
226                         Assert.IsTrue (!File.Exists (file_path), "A2");
227                         Assert.IsTrue (!File.Exists (file_path2), "A3");
228                 }
229
230                 [Test]
231                 [Category ("NotWorking")]
232                 public void TestDelete7 ()
233                 {
234                         Engine engine;
235                         Project project;
236                         string file_path = Path.Combine (path, "delete.txt");
237
238                         using (File.CreateText (file_path)) { }
239
240                         string documentString = @"
241                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
242                                         <PropertyGroup>
243                                                 <FolderToDelete>" + path + @"</FolderToDelete>
244                                                 <FileToDelete>delete</FileToDelete>
245                                                 <ExtToDelete>txt</ExtToDelete>
246                                         </PropertyGroup>
247                                         <Target Name='1'>
248                                                 <Delete Files='$(FolderToDelete)\$(FileToDelete).$(ExtToDelete)'/>
249                                         </Target>
250                                 </Project>
251                         ";
252
253                         engine = new Engine (Consts.BinPath);
254                         project = engine.CreateNewProject ();
255                         project.LoadXml (documentString);
256
257                         Assert.IsTrue (project.Build ("1"), "A1");
258                         Assert.IsTrue (!File.Exists (file_path), "A2");
259                 }
260
261         }
262 }