2009-05-18 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / various / Items.cs
1 //
2 // Items.cs
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //   Ankit Jain (jankit@novell.com)
7 //
8 // (C) 2006 Marek Sieradzki
9 // Copyright 2009 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 using System;
31 using System.Text;
32 using System.Xml;
33 using Microsoft.Build.BuildEngine;
34 using NUnit.Framework;
35
36 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
37         [TestFixture]
38         public class Items {
39                 private string GetItems (Project proj, string name)
40                 {
41                         BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
42                         string str = String.Empty;
43                         if (big == null)
44                                 return str;
45
46                         foreach (BuildItem bi in big) {
47                                 if (str == String.Empty)
48                                         str = bi.FinalItemSpec;
49                                 else 
50                                         str += ";" + bi.FinalItemSpec;
51                         }
52                         
53                         return str;
54                 }
55
56                 private void CheckItems (Project proj, string name, string prefix, params string [] values)
57                 {
58                         BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
59                         if (big == null) {
60                                 Assert.Fail ("{0}: Item corresponding '{1}' not found.", prefix, name);
61                                 return;
62                         }
63
64                         if (values.Length != big.Count) {
65                                 Console.Write ("Expected> ");
66                                 foreach (string s in values)
67                                         Console.Write ("{0}|", s);
68                                 Console.WriteLine ();
69                                 Console.Write ("Actual> ");
70                                 foreach (BuildItem item in big)
71                                         Console.Write ("{0}|", item.FinalItemSpec);
72                                 Console.WriteLine ();
73                                 Assert.AreEqual (values.Length, big.Count, String.Format ("{0}: Number of items", prefix));
74                         }
75                         for (int i = 0; i < values.Length; i ++)
76                                 Assert.AreEqual (values [i], big [i].FinalItemSpec,
77                                         String.Format ("{0}: Item named {1}, numbered {2}", prefix, name, i));
78                 }
79
80                 [Test]
81                 public void TestItems1 ()
82                 {
83                         Engine engine = new Engine (Consts.BinPath);
84                         Project proj = engine.CreateNewProject ();
85
86                         string documentString = @"
87                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
88                                         <ItemGroup>
89                                                 <Item0 Include='A' />
90                                                 <Item1 Include='A;B;C' />
91                                                 <Item2 Include='@(Item1);A;D' />
92                                                 <Item3 Include='@(Item2)' Exclude='A' />
93                                                 <Item4 Include='@(Item1);Q' Exclude='@(Item2)' />
94                                                 <Item5 Include='@(Item1)' Exclude='@(Item2)' />
95                                                 <Item6 Include='@(Item2)' Exclude='@(Item1)' />
96                                                 <Item7 Include='@(item_that_doesnt_exist)' />
97                                         </ItemGroup>
98                                 </Project>
99                         ";
100
101                         proj.LoadXml (documentString);
102                         CheckItems (proj, "Item0", "A1", "A");
103                         CheckItems (proj, "Item1", "A2", "A", "B", "C");
104                         CheckItems (proj, "Item2", "A3", "A", "B", "C", "A", "D");
105                         CheckItems (proj, "Item3", "A4", "B", "C", "D");
106                         CheckItems (proj, "Item4", "A5", "Q");
107                         CheckItems (proj, "Item5", "A6");
108                         CheckItems (proj, "Item6", "A7", "D");
109                         CheckItems (proj, "Item7", "A8");
110                 }
111
112                 [Test]
113                 public void TestItems2 ()
114                 {
115                         Engine engine = new Engine (Consts.BinPath);
116                         Project proj = engine.CreateNewProject ();
117
118                         string documentString = @"
119                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
120                                         <ItemGroup>
121                                                 <Item1 Include='A;B;C' />
122                                                 <Item2 Include=""@(Item1,'-')"" />
123                                                 <Item3 Include=""@(Item1,'xx')"" />
124                                         </ItemGroup>
125                                 </Project>
126                         ";
127
128                         proj.LoadXml (documentString);
129
130                         CheckItems (proj, "Item2", "A1", "A-B-C");
131                         CheckItems (proj, "Item3", "A2", "AxxBxxC");
132                 }
133
134                 [Test]
135                 public void TestItems3 ()
136                 {
137                         Engine engine = new Engine (Consts.BinPath);
138                         Project proj = engine.CreateNewProject ();
139
140                         string documentString = @"
141                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
142                                         <ItemGroup>
143                                                 <Item1 Include='A;B;C' />
144                                                 <Item2 Include=""@(Item1, '-')"" />
145                                         </ItemGroup>
146                                 </Project>
147                         ";
148
149                         proj.LoadXml (documentString);
150
151                         CheckItems (proj, "Item2", "A1", "A-B-C");
152                 }
153         
154
155                 [Test]
156                 public void TestItems4 ()
157                 {
158                         Engine engine = new Engine (Consts.BinPath);
159                         Project proj = engine.CreateNewProject ();
160
161                         string documentString = @"
162                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
163                                         <ItemGroup>
164                                                 <Item1 Include='A;B;C' />
165                                                 <Item2 Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
166                                                 <ItemT1 Include=""@(Item1->'%(Identity)')"" />
167                                                 <ItemT2 Include=""@(Item1->'%(Identity)%(Identity)')"" />
168                                                 <ItemT3 Include=""@(Item1->'(-%(Identity)-)')"" />
169                                                 <ItemT4 Include=""@(Item2->'%(Extension)')"" />
170                                                 <ItemT5 Include=""@(Item2->'%(Filename)/%(Extension)')"" />
171                                         </ItemGroup>
172                                 </Project>
173                         ";
174
175                         proj.LoadXml (documentString);
176
177                         CheckItems (proj, "ItemT1", "A1", "A", "B", "C");
178                         CheckItems (proj, "ItemT2", "A2", "AA", "BB", "CC");
179                         CheckItems (proj, "ItemT3", "A3", "(-A-)", "(-B-)", "(-C-)");
180                         CheckItems (proj, "ItemT4", "A4", ".txt", ".txt", ".zip", ".zip");
181                         CheckItems (proj, "ItemT5", "A5", "B/.txt", "C/.txt", "B/.zip", "C/.zip");
182                 }
183
184                 [Test]
185                 [Category ("NotWorking")]
186                 public void TestItems5 ()
187                 {
188                         Engine engine = new Engine (Consts.BinPath);
189                         Project proj = engine.CreateNewProject ();
190
191                         string documentString = @"
192                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
193                                         <ItemGroup>
194                                                 <Item Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
195                                                 <ItemT Include=""@(Item->'%(RelativeDir)X/%(Filename)')"" />
196                                         </ItemGroup>
197                                 </Project>
198                         ";
199
200                         proj.LoadXml (documentString);
201
202                         CheckItems (proj, "ItemT", "A1", @"A\X/B", @"A\X/C", @"B\X/B", @"B\X/C");
203                 }
204
205                 [Test]
206                 [Category ("NotWorking")]
207                 public void TestItems6 ()
208                 {
209                         Engine engine = new Engine (Consts.BinPath);
210                         Project proj = engine.CreateNewProject ();
211
212                         string documentString = @"
213                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
214                                         <PropertyGroup>
215                                                 <A>A</A>
216                                         </PropertyGroup>
217
218                                         <ItemGroup>
219                                                 <Item1 Include='A;B;C' />
220                                                 <Item2 Include='%(A.B)' />
221                                                 <Item3 Include='$(Z)' />
222                                                 <Item4 Include=""@(Item1, '$(A)')"" />
223                                                 <Item5 Include=""@(Item1, '%(A)')"" />
224                                                 <Item6 Include=""@(Item1, '@(A)')"" />
225                                                 <Item7 Include=""@(Item1-> '%(Filename)')"" />
226                                         </ItemGroup>
227                                 </Project>
228                         ";
229
230                         proj.LoadXml (documentString);
231
232                         CheckItems (proj, "Item2", "A1", "%(A.B)");
233                         CheckItems (proj, "Item3", "A2");
234                         CheckItems (proj, "Item4", "A3", "AABAC");
235                         CheckItems (proj, "Item5", "A4", "A%(A)B%(A)C");
236                         CheckItems (proj, "Item6", "A6", "A@(A)B@(A)C");
237                         CheckItems (proj, "Item7", "A6", "A", "B", "C");
238                 }
239
240                 // The expression "@(Item1, '@(A,'')')" cannot be used in this context. 
241                 // Item lists cannot be concatenated with other strings where an item list is expected. 
242                 // Use a semicolon to separate multiple item lists.
243                 [Test]
244                 [ExpectedException (typeof (InvalidProjectFileException))]
245                 [Category ("NotWorking")]
246                 public void TestItems7 ()
247                 {
248                         Engine engine = new Engine (Consts.BinPath);
249                         Project proj = engine.CreateNewProject ();
250
251                         string documentString = @"
252                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
253                                         <ItemGroup>
254                                                 <Item1 Include='A;B;C' />
255                                                 <Item7 Include=""@(Item1, '@(A,'')')"" />
256                                         </ItemGroup>
257                                 </Project>
258                         ";
259
260                         proj.LoadXml (documentString);
261                 }
262
263                 // The expression "@(Item1, '@(A->'')')" cannot be used in this context.
264                 // Item lists cannot be concatenated with other strings where an item list is expected.
265                 // Use a semicolon to separate multiple item lists.
266                 [Test]
267                 [ExpectedException (typeof (InvalidProjectFileException))]
268                 [Category ("NotWorking")]
269                 public void TestItems8 ()
270                 {
271                         Engine engine = new Engine (Consts.BinPath);
272                         Project proj = engine.CreateNewProject ();
273
274                         string documentString = @"
275                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
276                                         <ItemGroup>
277                                                 <Item1 Include='A;B;C' />
278                                                 <Item8 Include=""@(Item1, '@(A->'')')"" />
279                                         </ItemGroup>
280                                 </Project>
281                         ";
282
283                         proj.LoadXml (documentString);
284                 }
285
286                 // The expression "@(Item1, '@(A->'','')')" cannot be used in this context.
287                 // Item lists cannot be concatenated with other strings where an item list is expected.
288                 // Use a semicolon to separate multiple item lists.
289                 [Test]
290                 [ExpectedException (typeof (InvalidProjectFileException))]
291                 [Category ("NotWorking")]
292                 public void TestItems9 ()
293                 {
294                         Engine engine = new Engine (Consts.BinPath);
295                         Project proj = engine.CreateNewProject ();
296
297                         string documentString = @"
298                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
299                                         <ItemGroup>
300                                                 <Item1 Include='A;B;C' />
301                                                 <Item9 Include=""@(Item1, '@(A->'','')')"" />
302                                         </ItemGroup>
303                                 </Project>
304                         ";
305
306                         proj.LoadXml (documentString);
307                 }
308
309                 [Test]
310                 public void TestItemsInTarget1 ()
311                 {
312                         Engine engine = new Engine (Consts.BinPath);
313                         Project proj = engine.CreateNewProject ();
314
315                         string documentString = @"
316                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
317                                         <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
318                                         <PropertyGroup>
319                                                 <A>A</A>
320                                         </PropertyGroup>
321                                         <ItemGroup>
322                                                 <A Include='A;B;C' />
323                                         </ItemGroup>
324
325                                         <Target Name='1'>
326                                                 <StringTestTask Property='@(A)@(Z)'>
327                                                         <Output TaskParameter='Property' PropertyName='P1' />
328                                                 </StringTestTask>
329                                                 <StringTestTask Property=""@(A,'')"">
330                                                         <Output TaskParameter='Property' PropertyName='P2' />
331                                                 </StringTestTask>
332                                                 <StringTestTask Property=""@(A,'@(A)')"">
333                                                         <Output TaskParameter='Property' PropertyName='P3' />
334                                                 </StringTestTask>
335                                                 <StringTestTask Property=""@(A,'$(A)')"">
336                                                         <Output TaskParameter='Property' PropertyName='P4' />
337                                                 </StringTestTask>
338                                                 <StringTestTask Property=""@(A,'@(A,'')')"">
339                                                         <Output TaskParameter='Property' PropertyName='P5' />
340                                                 </StringTestTask>
341                                                 <StringTestTask Property=""%(A.Filename)"">
342                                                         <Output TaskParameter='Property' ItemName='I1' />
343                                                 </StringTestTask>
344                                                 <StringTestTask Property=""@(A) %(Filename)"">
345                                                         <Output TaskParameter='Property' ItemName='I2' />
346                                                 </StringTestTask>
347                                         </Target>
348                                 </Project>
349                         ";
350
351                         proj.LoadXml (documentString);
352                         Assert.IsTrue (proj.Build ("1"), "A0, Build failed");
353
354                         Assert.AreEqual ("A;B;C", proj.GetEvaluatedProperty ("P1"), "A1");
355                         Assert.AreEqual ("ABC", proj.GetEvaluatedProperty ("P2"), "A2");
356                         Assert.AreEqual ("A@(A)B@(A)C", proj.GetEvaluatedProperty ("P3"), "A3");
357                         Assert.AreEqual ("AABAC", proj.GetEvaluatedProperty ("P4"), "A4");
358                         Assert.AreEqual ("@(A,'ABC')", proj.GetEvaluatedProperty ("P5"), "A5");
359                         CheckItems (proj, "I1", "A6", "A", "B", "C");
360                         CheckItems (proj, "I2", "A7", "A A", "B B", "C C");
361                 }
362
363                 [Test]
364                 [Category ("NotWorking")]
365                 public void TestItemsInTarget2 ()
366                 {
367                         Engine engine = new Engine (Consts.BinPath);
368                         Project proj = engine.CreateNewProject ();
369
370                         string documentString = @"
371                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
372                                         <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
373                                         <ItemGroup>
374                                                 <A Include='A;B;C' />
375                                         </ItemGroup>
376
377                                         <Target Name='1'>
378                                                 <StringTestTask Property=""%(Filename)"">
379                                                         <Output TaskParameter='Property' ItemName='I2' />
380                                                 </StringTestTask>
381                                         </Target>
382                                 </Project>
383                         ";
384
385                         proj.LoadXml (documentString);
386                         Assert.IsFalse (proj.Build ("1"), "A1");
387                 }
388
389                 [Test]
390                 public void TestItemsInTarget3 ()
391                 {
392                         Engine engine = new Engine (Consts.BinPath);
393                         Project proj = engine.CreateNewProject ();
394
395                         string documentString = @"
396                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
397                                         <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
398                                         <PropertyGroup>
399                                                 <A>A</A>
400                                                 <B>A;B</B>
401                                                 <C>A;;</C>
402                                         </PropertyGroup>
403                                         <ItemGroup>
404                                                 <A Include='A;B;C' />
405                                         </ItemGroup>";
406
407                         documentString += CreateTargetFragment ("StringTestTask", "Array", "Array", "I",
408                                         new string [] {
409                                                 "$(A)$(A)",
410                                                 "$(B)$(B)",
411                                                 "$(C)",
412                                                 "$(C)$(C)",
413                                                 "@(A);$(C)",
414                                                 "@(A);A;B;C",
415                                                 "Foo;@(A)",
416                                                 "@(A);Foo"
417                                         }) + "</Project>";
418
419                         proj.LoadXml (documentString);
420                         Assert.IsTrue (proj.Build ("1"), "Build failed");
421
422                         CheckItems (proj, "I0", "A0", "AA");
423                         CheckItems (proj, "I1", "A1", "A", "BA", "B");
424                         CheckItems (proj, "I2", "A2", "A");
425                         CheckItems (proj, "I3", "A3", "A", "A");
426                         CheckItems (proj, "I4", "A4", "A", "B", "C", "A");
427                         CheckItems (proj, "I5", "A5", "A", "B", "C", "A", "B", "C");
428                         CheckItems (proj, "I6", "A6", "Foo", "A", "B", "C");
429                         CheckItems (proj, "I7", "A7", "A", "B", "C", "Foo");
430                 }
431
432                 [Test]
433                 //Test with ITaskItem[]
434                 public void TestItemsInTarget3a ()
435                 {
436                         Engine engine = new Engine (Consts.BinPath);
437                         Project proj = engine.CreateNewProject ();
438
439                         string documentString = @"
440                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
441                                         <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
442                                         <PropertyGroup>
443                                                 <A>A</A>
444                                                 <B>A;B</B>
445                                                 <C>A;;</C>
446                                         </PropertyGroup>
447                                         <ItemGroup>
448                                                 <A Include='A;B;C' />
449                                                 <B Include='Foo;' />
450                                         </ItemGroup>";
451
452                         documentString += CreateTargetFragment ("BatchingTestTask", "Sources", "Output", "I",
453                                         new string [] {
454                                                 "$(A)$(A)",
455                                                 "$(B)$(B)",
456                                                 "$(C)",
457                                                 "$(C)$(C)",
458                                                 "$(C)   $(C)",
459                                                 "  $(C)   Foo    $(C)  Bar ; $(B)   ",
460                                                 "@(A);$(C)",
461                                                 "@(A);A;B;C",
462                                         }) + "</Project>";
463
464
465                         proj.LoadXml (documentString);
466                         Assert.IsTrue (proj.Build ("1"), "Build failed");
467
468                         CheckItems (proj, "I0", "A0", "AA");
469                         CheckItems (proj, "I1", "A1", "A", "BA", "B");
470                         CheckItems (proj, "I2", "A2", "A");
471                         CheckItems (proj, "I3", "A3", "A", "A");
472                         CheckItems (proj, "I4", "A4", "A", "A");
473                         CheckItems (proj, "I5", "A5", "A", "Foo    A", "Bar", "A", "B");
474                         CheckItems (proj, "I6", "A6", "A", "B", "C", "A");
475                         CheckItems (proj, "I7", "A7", "A", "B", "C", "A", "B", "C");
476                 }
477
478                 [Test]
479                 //Test with string[]
480                 public void TestItemsInTarget3b ()
481                 {
482                         Engine engine = new Engine (Consts.BinPath);
483                         Project proj = engine.CreateNewProject ();
484
485                         string documentString = @"
486                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
487                                         <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
488                                         <PropertyGroup>
489                                                 <A>A</A>
490                                                 <B>A;B</B>
491                                                 <C>A;;</C>
492                                         </PropertyGroup>
493                                         <ItemGroup>
494                                                 <A Include='A;B;;;C' />
495                                         </ItemGroup>";
496
497                         documentString += CreateTargetFragment ("BatchingTestTask", "Strings", "StringsOutput", "I",
498                                         new string [] {
499                                                 "$(A)$(A)",
500                                                 "$(B)$(B)",
501                                                 "$(C)",
502                                                 "$(C)$(C)",
503                                                 "$(C) $(C) $(C)Bar$(C)",
504                                                 "@(A);$(C)",
505                                                 "@(A);A;B;C"
506                                         }) + "</Project>";
507
508                         proj.LoadXml (documentString);
509                         Assert.IsTrue (proj.Build ("1"), "Build failed");
510
511                         CheckItems (proj, "I0", "A0", "AA");
512                         CheckItems (proj, "I1", "A1", "A", "BA", "B");
513                         CheckItems (proj, "I2", "A2", "A");
514                         CheckItems (proj, "I3", "A3", "A", "A");
515                         CheckItems (proj, "I4", "A4", "A", "A", "A", "BarA");
516                         CheckItems (proj, "I5", "A5", "A", "B", "C", "A");
517                         CheckItems (proj, "I6", "A6", "A", "B", "C", "A", "B", "C");
518                 }
519
520                 [Test]
521                 //Test with string
522                 public void TestItemsInTarget3c ()
523                 {
524                         Engine engine = new Engine (Consts.BinPath);
525                         Project proj = engine.CreateNewProject ();
526
527                         string documentString = @"
528                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
529                                         <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
530                                         <PropertyGroup>
531                                                 <A>A</A>
532                                                 <B>A;B</B>
533                                                 <C>A;;</C>
534                                                 <D>$(C);Foo</D>
535                                         </PropertyGroup>
536                                         <ItemGroup>
537                                                 <A Include='A;B;;;C' />
538                                         </ItemGroup>";
539
540                         documentString += CreateTargetFragment ("BatchingTestTask", "SingleString", "SingleStringOutput", "I",
541                                         new string [] {
542                                                 "$(A)$(A)",
543                                                 "$(B)$(B)",
544                                                 "$(C)",
545                                                 "$(C)$(C)",
546                                                 "$(C) $(C)",
547                                                 "@(A);$(C)",
548                                                 "@(A);A;B;C",
549                                                 "@(A) $(C) @(A)"
550                                         }) + "</Project>";
551
552                         proj.LoadXml (documentString);
553                         Assert.IsTrue (proj.Build ("1"), "Build failed");
554
555                         BuildProperty bp = proj.EvaluatedProperties ["D"];
556                         Assert.AreEqual ("$(C);Foo", bp.Value, "B0");
557                         Assert.AreEqual ("A;;;Foo", bp.FinalValue, "B1");
558
559                         bp = proj.EvaluatedProperties ["C"];
560                         Assert.AreEqual ("A;;", bp.Value, "B3");
561                         Assert.AreEqual ("A;;", bp.FinalValue, "B4");
562
563                         CheckItems (proj, "I0", "A0", "AA");
564                         CheckItems (proj, "I1", "A1", "A;BA;B");
565                         CheckItems (proj, "I2", "A2", "A;;");
566                         CheckItems (proj, "I3", "A3", "A;;A;;");
567                         CheckItems (proj, "I4", "A4", "A;; A;;");
568                         CheckItems (proj, "I5", "A5", "A;B;C;A;;");
569                         CheckItems (proj, "I6", "A6", "A;B;C;A;B;C");
570                         CheckItems (proj, "I7", "A7", "A;B;C A;; A;B;C");
571                 }
572
573                 [Test]
574                 public void TestSingleTaskItemError1 ()
575                 {
576                         CheckSingleTaskItemProject ("$(B)$(B)");
577                 }
578
579                 [Test]
580                 public void TestSingleTaskItemError2 ()
581                 {
582                         CheckSingleTaskItemProject ("$(C)$(C)");
583                 }
584
585                 [Test]
586                 public void TestSingleTaskItemError3 ()
587                 {
588                         CheckSingleTaskItemProject ("$(C) $(C)");
589                 }
590
591                 [Test]
592                 public void TestSingleTaskItemError4 ()
593                 {
594                         CheckSingleTaskItemProject ("@(A)");
595                 }
596
597                 [Test]
598                 public void TestSingleTaskItemError5 ()
599                 {
600                         CheckSingleTaskItemProject ("@(A);$(C))");
601                 }
602
603                 [Test]
604                 public void TestSingleTaskItemError6 ()
605                 {
606                         CheckSingleTaskItemProject ("@(A);A;B;C");
607                 }
608
609                 [Test]
610                 public void TestSingleTaskItemError7 ()
611                 {
612                         CheckSingleTaskItemProject ("@(Item1)$(C)");
613                 }
614
615                 [Test]
616                 public void TestSingleTaskItemError8 ()
617                 {
618                         CheckSingleTaskItemProject ("$(B).foo");
619                 }
620
621                 [Test]
622                 public void TestSingleTaskItem1 ()
623                 {
624                         Project proj = BuildProjectForSingleTaskItem ("$(D)$(C)");
625                         CheckItems (proj, "I0", "A0", "A");
626                 }
627
628                 [Test]
629                 public void TestSingleTaskItem2 ()
630                 {
631                         Project proj = BuildProjectForSingleTaskItem ("@(Item1)");
632                         CheckItems (proj, "I0", "A0", "F");
633                 }
634
635                 [Test]
636                 public void TestSingleTaskItem3 ()
637                 {
638                         Project proj = BuildProjectForSingleTaskItem ("$(A).foo");
639                         CheckItems (proj, "I0", "A0", "A.foo");
640                 }
641
642                 [Test]
643                 public void TestSingleTaskItem4 ()
644                 {
645                         Project proj = BuildProjectForSingleTaskItem ("$(C)");
646                         CheckItems (proj, "I0", "A0", "A");
647                 }
648
649                 void CheckSingleTaskItemProject (string expression)
650                 {
651                         string documentString = CreateProjectForSingleTaskItem (expression);
652                         Engine engine = new Engine (Consts.BinPath);
653                         Project proj = engine.CreateNewProject ();
654                         proj.LoadXml (documentString);
655                         Assert.IsFalse (proj.Build ("1"), "Build should've failed");
656                 }
657
658                 Project BuildProjectForSingleTaskItem (string expression)
659                 {
660                         string documentString = CreateProjectForSingleTaskItem (expression);
661                         Engine engine = new Engine (Consts.BinPath);
662                         Project proj = engine.CreateNewProject ();
663                         proj.LoadXml (documentString);
664                         Assert.IsTrue (proj.Build ("1"), "Build failed");
665
666                         return proj;
667                 }
668
669                 string CreateProjectForSingleTaskItem (string expression)
670                 {
671                         return @"
672                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
673                                         <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
674                                         <PropertyGroup>
675                                                 <A>A</A>
676                                                 <B>A;B</B>
677                                                 <C>A;;</C>
678                                                 <D></D>
679                                         </PropertyGroup>
680                                         <ItemGroup>
681                                                 <A Include='A;B;C' />
682                                                 <Item1 Include='F' />
683                                         </ItemGroup>
684
685                                         <Target Name='1'>
686                                                 <BatchingTestTask SingleTaskItem='" + expression + @"'>
687                                                         <Output TaskParameter='SingleStringOutput' ItemName='I0' />
688                                                 </BatchingTestTask>
689                                         </Target>
690                                 </Project>";
691                 }
692
693                 string CreateTargetFragment (string taskname, string task_param_in, string task_param_out, string item_prefix,
694                                 string [] args)
695                 {
696                         StringBuilder sb = new StringBuilder ();
697
698                         sb.Append ("<Target Name='1'>");
699                         for (int i = 0; i < args.Length; i ++) {
700                                 sb.AppendFormat ("<{0} {1}='{2}'>\n", taskname, task_param_in, args [i]);
701                                 sb.AppendFormat ("\t<Output TaskParameter='{0}' ItemName='{1}{2}' />\n", task_param_out, item_prefix, i);
702                                 sb.AppendFormat ("</{0}>\n", taskname);
703                         }
704                         sb.Append ("</Target>");
705
706                         return sb.ToString ();
707                 }
708
709                 [Test]
710                 public void TestItemsInTarget4 ()
711                 {
712                         Engine engine = new Engine (Consts.BinPath);
713                         Project proj = engine.CreateNewProject ();
714
715                         string documentString = @"
716                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
717                                         <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
718                                         <ItemGroup>
719                                                 <A Include='A;B;C' />
720                                         </ItemGroup>
721                                         <Target Name='1'>
722                                                 <StringTestTask Array='@(A)@(A)'>
723                                                         <Output TaskParameter='Array' ItemName='I1' />
724                                                 </StringTestTask>
725                                         </Target>
726                                 </Project>
727                         ";
728
729                         proj.LoadXml (documentString);
730                         Assert.IsFalse (proj.Build ("1"));
731                 }
732
733                 [Test]
734                 public void TestItemsInTarget5 ()
735                 {
736                         Engine engine = new Engine (Consts.BinPath);
737                         Project proj = engine.CreateNewProject ();
738
739                         string documentString = @"
740                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
741                                         <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
742                                         <ItemGroup>
743                                                 <A Include='A;B;C' />
744                                         </ItemGroup>
745                                         <Target Name='1'>
746                                                 <StringTestTask Array='@(A)AAA'>
747                                                         <Output TaskParameter='Array' ItemName='I1' />
748                                                 </StringTestTask>
749                                         </Target>
750                                 </Project>
751                         ";
752
753                         proj.LoadXml (documentString);
754                         Assert.IsFalse (proj.Build ("1"));
755                 }
756
757                 [Test]
758                 public void TestItemsInTarget6 ()
759                 {
760                         Engine engine = new Engine (Consts.BinPath);
761                         Project proj = engine.CreateNewProject ();
762
763                         string documentString = @"
764                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
765                                         <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
766                                         <ItemGroup>
767                                                 <A Include='A;B;C' />
768                                         </ItemGroup>
769                                         <PropertyGroup>
770                                                 <A>A</A>
771                                         </PropertyGroup>
772                                         <Target Name='1'>
773                                                 <StringTestTask Array='@(A)$(A)'>
774                                                         <Output TaskParameter='Array' ItemName='I1' />
775                                                 </StringTestTask>
776                                         </Target>
777                                 </Project>
778                         ";
779
780                         proj.LoadXml (documentString);
781                         Assert.IsFalse (proj.Build ("1"));
782                 }
783
784                 [Test]
785                 public void TestItemsInTarget7 ()
786                 {
787                         Engine engine = new Engine (Consts.BinPath);
788                         Project proj = engine.CreateNewProject ();
789
790                         string documentString = @"
791                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
792                                         <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
793                                         <ItemGroup>
794                                                 <A Include='A;B;C' />
795                                                 <B Include='Foo;' />
796                                         </ItemGroup>
797                                         <Target Name='1'>
798                                                 <BatchingTestTask SingleTaskItem='Bar%(B.Identity)@(A)' />
799                                         </Target>
800                                 </Project>
801                         ";
802
803                         proj.LoadXml (documentString);
804                         Assert.IsFalse (proj.Build ("1"));
805                 }
806
807                 [Test]
808                 public void TestItemsInTarget8 ()
809                 {
810                         Engine engine = new Engine (Consts.BinPath);
811                         Project proj = engine.CreateNewProject ();
812
813                         string documentString = @"
814                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
815                                         <PropertyGroup>
816                                                 <Foo>Five</Foo>
817                                         </PropertyGroup>
818                                         <ItemGroup>
819                                                 <A Include='A'>
820                                                         <M>True</M>
821                                                         <M>False</M>
822                                                 </A>
823                                         </ItemGroup>
824                                 </Project>
825                         ";
826
827                         proj.LoadXml (documentString);
828
829                         Assert.AreEqual (1, proj.EvaluatedItems.Count, "A1");
830                         BuildItem bi = proj.EvaluatedItems [0];
831                         Assert.AreEqual ("False", bi.GetMetadata ("M"), "A2");
832                 }
833
834
835                 [Test]
836                 public void TestItemsInTarget9 ()
837                 {
838                         Engine engine = new Engine (Consts.BinPath);
839                         Project proj = engine.CreateNewProject ();
840
841                         string documentString = @"
842                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
843                                         <PropertyGroup>
844                                                 <Foo>Five</Foo>
845                                         </PropertyGroup>
846                                         <ItemGroup>
847                                                 <A Include='A'>
848                                                         <M Condition="" '$(Foo)' == 'Five' "">True</M>
849                                                         <M Condition="" '$(Foo)' != 'Five' "">False</M>
850                                                 </A>
851                                         </ItemGroup>
852                                 </Project>
853                         ";
854
855                         proj.LoadXml (documentString);
856
857                         Assert.AreEqual (1, proj.EvaluatedItems.Count, "A1");
858                         BuildItem bi = proj.EvaluatedItems [0];
859                         Assert.AreEqual ("True", bi.GetMetadata ("M"), "A2");
860                         Assert.AreEqual (0, bi.Condition.Length, "A3");
861
862                         BuildItemGroup big = proj.GetEvaluatedItemsByNameIgnoringCondition ("A");
863                         Assert.AreEqual (1, big.Count, "A4");
864                         bi = big [0];
865                         Assert.AreEqual ("True", bi.GetMetadata ("M"), "A5");
866                         Assert.AreEqual ("True", bi.GetEvaluatedMetadata ("M"), "A6");
867
868                         /*proj.SetProperty ("Foo", "Six");
869                         proj.Build ();
870                         bi = proj.GetEvaluatedItemsByName ("A") [0];
871                         Assert.AreEqual ("False", bi.GetMetadata ("M"), "A7");
872                         Assert.AreEqual ("False", bi.GetEvaluatedMetadata ("M"), "A7a");
873                         Assert.AreEqual (0, bi.Condition.Length, "A8");
874
875                         big = proj.GetEvaluatedItemsByNameIgnoringCondition ("A");
876                         Assert.AreEqual (1, big.Count, "A9");
877                         bi = big [0];
878                         Assert.AreEqual ("True", bi.GetMetadata ("M"), "A10");
879                         Assert.AreEqual ("True", bi.GetEvaluatedMetadata ("M"), "A11");*/
880                 }
881         }
882 }