5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2006 Marek Sieradzki
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.
30 using Microsoft.Build.BuildEngine;
31 using NUnit.Framework;
33 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
35 public class EvaluationOrder {
36 private string GetItems (Project proj, string name)
38 BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
39 string str = String.Empty;
43 foreach (BuildItem bi in big) {
44 if (str == String.Empty)
45 str = bi.FinalItemSpec;
47 str += ";" + bi.FinalItemSpec;
54 [Category ("NotWorking")]
55 public void TestOrder0 ()
57 Engine engine = new Engine (Consts.BinPath);
58 Project proj = engine.CreateNewProject ();
60 string documentString = @"
61 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
68 <Property>@(Item)$(A)$(B)</Property>
73 proj.LoadXml (documentString);
75 Assert.AreEqual ("@(Item)A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
76 Assert.AreEqual ("@(Item)$(A)$(B)", proj.EvaluatedProperties ["Property"].Value, "A2");
77 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
81 [Category ("NotWorking")]
82 public void TestOrder1 ()
84 Engine engine = new Engine (Consts.BinPath);
85 Project proj = engine.CreateNewProject ();
87 string documentString = @"
88 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
94 <Property>@(Item)</Property>
99 proj.LoadXml (documentString);
101 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
102 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
103 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
107 [Category ("NotWorking")]
108 public void TestOrder2 ()
110 Engine engine = new Engine (Consts.BinPath);
111 Project proj = engine.CreateNewProject ();
113 string documentString = @"
114 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
116 <Property>@(Item)</Property>
125 proj.LoadXml (documentString);
127 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
128 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
129 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
133 public void TestOrder3 ()
135 Engine engine = new Engine (Consts.BinPath);
136 Project proj = engine.CreateNewProject ();
138 string documentString = @"
139 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
141 <Property>A</Property>
145 <Item Include='$(Property)' />
150 proj.LoadXml (documentString);
152 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
153 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
154 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
158 public void TestOrder4 ()
160 Engine engine = new Engine (Consts.BinPath);
161 Project proj = engine.CreateNewProject ();
163 string documentString = @"
164 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
166 <Item Include='$(Property)' />
170 <Property>A</Property>
175 proj.LoadXml (documentString);
177 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
178 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
179 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
183 [Category ("NotWorking")]
184 public void TestOrder5 ()
186 Engine engine = new Engine (Consts.BinPath);
187 Project proj = engine.CreateNewProject ();
189 string documentString = @"
190 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
192 <Item Include='$(Property)' />
196 <Property>A</Property>
197 <Property2>@(Item)</Property2>
202 proj.LoadXml (documentString);
204 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
205 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
206 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
207 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].FinalValue, "A4");
208 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].Value, "A5");
212 [Category ("NotWorking")]
213 public void TestOrder6 ()
215 Engine engine = new Engine (Consts.BinPath);
216 Project proj = engine.CreateNewProject ();
218 string documentString = @"
219 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
222 <Item2 Include='$(Property)' />
226 <Property>@(Item)</Property>
231 proj.LoadXml (documentString);
233 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
234 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
235 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
236 Assert.AreEqual ("A", GetItems (proj, "Item2"), "A4");
240 public void TestImportOrder1 ()
242 Engine engine = new Engine (Consts.BinPath);
243 Project proj = engine.CreateNewProject ();
245 string documentString = @"
246 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
248 <Property>Test/resources/Import.csproj</Property>
251 <Import Project='$(Property)'/>
255 proj.LoadXml (documentString);
257 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
258 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
262 [ExpectedException (typeof (InvalidProjectFileException))]
263 public void TestImportOrder2 ()
265 Engine engine = new Engine (Consts.BinPath);
266 Project proj = engine.CreateNewProject ();
268 string documentString = @"
269 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
270 <Import Project='$(Property)'/>
273 <Property>Test/resources/Import.csproj</Property>
278 proj.LoadXml (documentString);
280 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
281 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
285 // NOTE: It will try to import "@(Item)" instead of Test/...
286 [ExpectedException (typeof (InvalidProjectFileException))]
287 [Category ("NotWorking")]
288 public void TestImportOrder3 ()
290 Engine engine = new Engine (Consts.BinPath);
291 Project proj = engine.CreateNewProject ();
293 string documentString = @"
294 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
296 <Item Include='Test/resources/Import.csproj' />
299 <Import Project='@(Item)'/>
303 proj.LoadXml (documentString);
305 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
306 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
310 // NOTE: It will try to import "@(Item)" instead of Test/...
311 [ExpectedException (typeof (InvalidProjectFileException))]
312 [Category ("NotWorking")]
313 public void TestImportOrder4 ()
315 Engine engine = new Engine (Consts.BinPath);
316 Project proj = engine.CreateNewProject ();
318 string documentString = @"
319 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
320 <Import Project='@(Item)'/>
323 <Item Include='Test/resources/Import.csproj' />
328 proj.LoadXml (documentString);
330 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
331 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
335 public void TestImportOrder5 ()
337 Engine engine = new Engine (Consts.BinPath);
338 Project proj = engine.CreateNewProject ();
340 string documentString = @"
341 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
343 <ImportedProperty>AnotherValue</ImportedProperty>
346 <Import Project='Test/resources/Import.csproj'/>
350 proj.LoadXml (documentString);
352 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
353 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
357 public void TestImportOrder6 ()
359 Engine engine = new Engine (Consts.BinPath);
360 Project proj = engine.CreateNewProject ();
362 string documentString = @"
363 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
364 <Import Project='Test/resources/Import.csproj'/>
367 <ImportedProperty>AnotherValue</ImportedProperty>
372 proj.LoadXml (documentString);
374 Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
375 Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
379 public void TestImportOrder7 ()
381 Engine engine = new Engine (Consts.BinPath);
382 Project proj = engine.CreateNewProject ();
384 string documentString = @"
385 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
386 <Import Project='Test/resources/Import.csproj'/>
389 <ImportedProperty>Another$(ImportedProperty)</ImportedProperty>
394 proj.LoadXml (documentString);
396 Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
397 Assert.AreEqual ("Another$(ImportedProperty)", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
401 public void TestUsingTaskOrder1 ()
403 Engine engine = new Engine (Consts.BinPath);
404 Project proj = engine.CreateNewProject ();
406 string documentString = @"
407 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
409 <Property>Test\resources\TestTasks.dll</Property>
412 <UsingTask AssemblyFile='$(Property)' TaskName='TrueTestTask' />
416 proj.LoadXml (documentString);
418 UsingTask [] ut = new UsingTask [1];
419 proj.UsingTasks.CopyTo (ut, 0);
421 Assert.AreEqual ("$(Property)", ut [0].AssemblyFile, "A1");