77b45eb5bc059022f7cb782e886c1b5d34b0de7a
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / various / EvaluationOrder.cs
1 //
2 // EvaluationOrder.cs
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2006 Marek Sieradzki
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.Xml;
30 using Microsoft.Build.BuildEngine;
31 using NUnit.Framework;
32
33 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
34         [TestFixture]
35         public class EvaluationOrder {
36                 string GetItems (Project proj, string name)
37                 {
38                         BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
39                         string str = String.Empty;
40                         if (big == null)
41                                 return str;
42                         
43                         foreach (BuildItem bi in big) {
44                                 if (str == String.Empty)
45                                         str = bi.FinalItemSpec;
46                                 else 
47                                         str += ";" + bi.FinalItemSpec;
48                         }
49                         
50                         return str;
51                 }
52
53                 [Test]
54                 public void TestOrder0 ()
55                 {
56                         Engine engine = new Engine (Consts.BinPath);
57                         Project proj = engine.CreateNewProject ();
58
59                         string documentString = @"
60                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
61                                         <ItemGroup>
62                                                 <Item Include='A' />
63                                         </ItemGroup>
64
65                                         <PropertyGroup>
66                                                 <A>A</A>
67                                                 <Property>@(Item)$(A)$(B)</Property>
68                                         </PropertyGroup>
69                                 </Project>
70                         ";
71
72                         proj.LoadXml (documentString);
73
74                         Assert.AreEqual ("@(Item)A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
75                         Assert.AreEqual ("@(Item)$(A)$(B)", proj.EvaluatedProperties ["Property"].Value, "A2");
76                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
77                 }
78
79                 [Test]
80                 public void TestOrder1 ()
81                 {
82                         Engine engine = new Engine (Consts.BinPath);
83                         Project proj = engine.CreateNewProject ();
84
85                         string documentString = @"
86                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
87                                         <ItemGroup>
88                                                 <Item Include='A' />
89                                         </ItemGroup>
90
91                                         <PropertyGroup>
92                                                 <Property>@(Item)</Property>
93                                         </PropertyGroup>
94                                 </Project>
95                         ";
96
97                         proj.LoadXml (documentString);
98
99                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
100                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
101                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
102                 }
103
104                 [Test]
105                 public void TestOrder2 ()
106                 {
107                         Engine engine = new Engine (Consts.BinPath);
108                         Project proj = engine.CreateNewProject ();
109
110                         string documentString = @"
111                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
112                                         <PropertyGroup>
113                                                 <Property>@(Item)</Property>
114                                         </PropertyGroup>
115
116                                         <ItemGroup>
117                                                 <Item Include='A' />
118                                         </ItemGroup>
119                                 </Project>
120                         ";
121
122                         proj.LoadXml (documentString);
123
124                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
125                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
126                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
127                 }
128
129                 [Test]
130                 public void TestOrder3 ()
131                 {
132                         Engine engine = new Engine (Consts.BinPath);
133                         Project proj = engine.CreateNewProject ();
134
135                         string documentString = @"
136                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
137                                         <PropertyGroup>
138                                                 <Property>A</Property>
139                                         </PropertyGroup>
140
141                                         <ItemGroup>
142                                                 <Item Include='$(Property)' />
143                                         </ItemGroup>
144                                 </Project>
145                         ";
146
147                         proj.LoadXml (documentString);
148
149                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
150                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
151                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
152                 }
153
154                 [Test]
155                 public void TestOrder4 ()
156                 {
157                         Engine engine = new Engine (Consts.BinPath);
158                         Project proj = engine.CreateNewProject ();
159
160                         string documentString = @"
161                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
162                                         <ItemGroup>
163                                                 <Item Include='$(Property)' />
164                                         </ItemGroup>
165
166                                         <PropertyGroup>
167                                                 <Property>A</Property>
168                                         </PropertyGroup>
169                                 </Project>
170                         ";
171
172                         proj.LoadXml (documentString);
173
174                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
175                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
176                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
177                 }
178
179                 [Test]
180                 public void TestOrder5 ()
181                 {
182                         Engine engine = new Engine (Consts.BinPath);
183                         Project proj = engine.CreateNewProject ();
184
185                         string documentString = @"
186                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
187                                         <ItemGroup>
188                                                 <Item Include='$(Property)' />
189                                         </ItemGroup>
190
191                                         <PropertyGroup>
192                                                 <Property>A</Property>
193                                                 <Property2>@(Item)</Property2>
194                                         </PropertyGroup>
195                                 </Project>
196                         ";
197
198                         proj.LoadXml (documentString);
199
200                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
201                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
202                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
203                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].FinalValue, "A4");
204                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].Value, "A5");
205                 }
206
207                 [Test]
208                 [Category ("NotWorking")]
209                 public void TestOrder6 ()
210                 {
211                         Engine engine = new Engine (Consts.BinPath);
212                         Project proj = engine.CreateNewProject ();
213
214                         string documentString = @"
215                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
216                                         <ItemGroup>
217                                                 <Item Include='A' />
218                                                 <Item2 Include='$(Property)' />
219                                         </ItemGroup>
220
221                                         <PropertyGroup>
222                                                 <Property>@(Item)</Property>
223                                         </PropertyGroup>
224                                 </Project>
225                         ";
226
227                         proj.LoadXml (documentString);
228
229                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
230                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
231                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
232                         Assert.AreEqual ("A", GetItems (proj, "Item2"), "A4");
233                 }
234
235                 [Test]
236                 [Category ("NotDotNet")]
237                 public void TestImportOrder1 ()
238                 {
239                         Engine engine = new Engine (Consts.BinPath);
240                         Project proj = engine.CreateNewProject ();
241
242                         string documentString = @"
243                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
244                                         <PropertyGroup>
245                                                 <Property>Test/resources/Import.csproj</Property>
246                                         </PropertyGroup>
247
248                                         <Import Project='$(Property)'/>
249                                 </Project>
250                         ";
251
252                         proj.LoadXml (documentString);
253
254                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
255                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
256                 }
257
258                 [Test]
259                 [Category ("NotDotNet")]
260                 [ExpectedException (typeof (InvalidProjectFileException))]
261                 public void TestImportOrder2 ()
262                 {
263                         Engine engine = new Engine (Consts.BinPath);
264                         Project proj = engine.CreateNewProject ();
265
266                         string documentString = @"
267                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
268                                         <Import Project='$(Property)'/>
269
270                                         <PropertyGroup>
271                                                 <Property>Test/resources/Import.csproj</Property>
272                                         </PropertyGroup>
273                                 </Project>
274                         ";
275
276                         proj.LoadXml (documentString);
277
278                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
279                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
280                 }
281
282                 [Test]
283                 // NOTE: It will try to import "@(Item)" instead of Test/...
284                 [ExpectedException (typeof (InvalidProjectFileException))]
285                 public void TestImportOrder3 ()
286                 {
287                         Engine engine = new Engine (Consts.BinPath);
288                         Project proj = engine.CreateNewProject ();
289
290                         string documentString = @"
291                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
292                                         <ItemGroup>
293                                                 <Item Include='Test/resources/Import.csproj' />
294                                         </ItemGroup>
295
296                                         <Import Project='@(Item)'/>
297                                 </Project>
298                         ";
299
300                         proj.LoadXml (documentString);
301
302                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
303                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
304                 }
305
306                 [Test]
307                 // NOTE: It will try to import "@(Item)" instead of Test/...
308                 [ExpectedException (typeof (InvalidProjectFileException))]
309                 public void TestImportOrder4 ()
310                 {
311                         Engine engine = new Engine (Consts.BinPath);
312                         Project proj = engine.CreateNewProject ();
313
314                         string documentString = @"
315                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
316                                         <Import Project='@(Item)'/>
317
318                                         <ItemGroup>
319                                                 <Item Include='Test/resources/Import.csproj' />
320                                         </ItemGroup>
321                                 </Project>
322                         ";
323
324                         proj.LoadXml (documentString);
325
326                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
327                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
328                 }
329
330                 [Test]
331                 [Category ("NotDotNet")]
332                 public void TestImportOrder5 ()
333                 {
334                         Engine engine = new Engine (Consts.BinPath);
335                         Project proj = engine.CreateNewProject ();
336
337                         string documentString = @"
338                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
339                                         <PropertyGroup>
340                                                 <ImportedProperty>AnotherValue</ImportedProperty>
341                                         </PropertyGroup>
342
343                                         <Import Project='Test/resources/Import.csproj'/>
344                                 </Project>
345                         ";
346
347                         proj.LoadXml (documentString);
348
349                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
350                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
351                 }
352
353                 [Test]
354                 [Category ("NotDotNet")]
355                 public void TestImportOrder6 ()
356                 {
357                         Engine engine = new Engine (Consts.BinPath);
358                         Project proj = engine.CreateNewProject ();
359
360                         string documentString = @"
361                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
362                                         <Import Project='Test/resources/Import.csproj'/>
363
364                                         <PropertyGroup>
365                                                 <ImportedProperty>AnotherValue</ImportedProperty>
366                                         </PropertyGroup>
367                                 </Project>
368                         ";
369
370                         proj.LoadXml (documentString);
371
372                         Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
373                         Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
374                 }
375
376                 [Test]
377                 [Category ("NotDotNet")]
378                 public void TestImportOrder7 ()
379                 {
380                         Engine engine = new Engine (Consts.BinPath);
381                         Project proj = engine.CreateNewProject ();
382
383                         string documentString = @"
384                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
385                                         <Import Project='Test/resources/Import.csproj'/>
386
387                                         <PropertyGroup>
388                                                 <ImportedProperty>Another$(ImportedProperty)</ImportedProperty>
389                                         </PropertyGroup>
390                                 </Project>
391                         ";
392
393                         proj.LoadXml (documentString);
394
395                         Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
396                         Assert.AreEqual ("Another$(ImportedProperty)", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
397                 }
398
399                 [Test]
400                 public void TestUsingTaskOrder1 ()
401                 {
402                         Engine engine = new Engine (Consts.BinPath);
403                         Project proj = engine.CreateNewProject ();
404
405                         string documentString = @"
406                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
407                                         <PropertyGroup>
408                                                 <Property>Test\resources\TestTasks.dll</Property>
409                                         </PropertyGroup>
410
411                                         <UsingTask AssemblyFile='$(Property)' TaskName='TrueTestTask' />
412                                 </Project>
413                         ";
414
415                         proj.LoadXml (documentString);
416
417                         UsingTask [] ut = new UsingTask [1];
418                         proj.UsingTasks.CopyTo (ut, 0);
419
420                         Assert.AreEqual ("$(Property)", ut [0].AssemblyFile, "A1");
421                 }
422         }
423 }