--- /dev/null
+//
+// Conditions.cs: Tests various conditions by checking if a property
+// is added to EvaluatedProperties.
+//
+// Author:
+// Marek Sieradzki (marek.sieradzki@gmail.com)
+//
+// (C) 2006 Marek Sieradzki
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+using System;
+using System.Xml;
+using Microsoft.Build.BuildEngine;
+using NUnit.Framework;
+
+namespace MonoTests.Microsoft.Build.BuildEngine.Various {
+ [TestFixture]
+ public class Conditions {
+
+ [Test]
+ public void TestCondition1 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <A Condition='true'></A>
+ <B Condition='false'></B>
+ <C Condition='TRUE'></C>
+ <D Condition='FALSE'></D>
+ <E Condition=''>A</E>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.IsNotNull (proj.EvaluatedProperties ["A"], "A1");
+ Assert.IsNull (proj.EvaluatedProperties ["B"], "A2");
+ Assert.IsNotNull (proj.EvaluatedProperties ["C"], "A3");
+ Assert.IsNull (proj.EvaluatedProperties ["D"], "A4");
+ Assert.IsNotNull (proj.EvaluatedProperties ["E"], "A5");
+ }
+
+ [Test]
+ public void TestCondition2 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <A Condition='true or true'></A>
+ <B Condition='false or false'></B>
+ <C Condition='true or false'></C>
+ <D Condition='false or true'></D>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.IsNotNull (proj.EvaluatedProperties ["A"], "A1");
+ Assert.IsNull (proj.EvaluatedProperties ["B"], "A2");
+ Assert.IsNotNull (proj.EvaluatedProperties ["C"], "A3");
+ Assert.IsNotNull (proj.EvaluatedProperties ["D"], "A4");
+ }
+
+ [Test]
+ public void TestCondition3 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <A Condition='true and true'></A>
+ <B Condition='false and false'></B>
+ <C Condition='true and false'></C>
+ <D Condition='false and true'></D>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.IsNotNull (proj.EvaluatedProperties ["A"], "A1");
+ Assert.IsNull (proj.EvaluatedProperties ["B"], "A2");
+ Assert.IsNull (proj.EvaluatedProperties ["C"], "A3");
+ Assert.IsNull (proj.EvaluatedProperties ["D"], "A4");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestCondition4 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <A Condition='!true'></A>
+ <B Condition='!false'></B>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.IsNull (proj.EvaluatedProperties ["A"], "A1");
+ Assert.IsNotNull (proj.EvaluatedProperties ["B"], "A2");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestCondition5 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <a Condition='-1 < 0'></a>
+ <b Condition='-1 <= 0'></b>
+ <c Condition='-1.0 < 0.0'></c>
+ <d Condition='-1.0 <= 0.0'></d>
+ <e Condition='-1.0 == 0.0'></e>
+ <f Condition='0.0 == 0.0'></f>
+ <g Condition='-1.0 != 0.0'></g>
+ <h Condition='0.0 != 0.0'></h>
+ <i Condition='1 > 0'></i>
+ <j Condition='1 >= 0'></j>
+ <k Condition='-1 > 0'></k>
+ <l Condition='-1 >= 0'></l>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.IsNotNull (proj.EvaluatedProperties ["a"], "A1");
+ Assert.IsNotNull (proj.EvaluatedProperties ["b"], "A2");
+ Assert.IsNotNull (proj.EvaluatedProperties ["c"], "A3");
+ Assert.IsNotNull (proj.EvaluatedProperties ["d"], "A4");
+ Assert.IsNull (proj.EvaluatedProperties ["e"], "A5");
+ Assert.IsNotNull (proj.EvaluatedProperties ["f"], "A6");
+ Assert.IsNotNull (proj.EvaluatedProperties ["g"], "A7");
+ Assert.IsNull (proj.EvaluatedProperties ["h"], "A8");
+ Assert.IsNotNull (proj.EvaluatedProperties ["i"], "A1");
+ Assert.IsNotNull (proj.EvaluatedProperties ["j"], "A2");
+ Assert.IsNull (proj.EvaluatedProperties ["k"], "A3");
+ Assert.IsNull (proj.EvaluatedProperties ["l"], "A4");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidProjectFileException))]
+ [Category ("NotWorking")]
+ public void TestIncorrectCondition1 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <A Condition='x'>A</A>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ }
+ }
+}
--- /dev/null
+//
+// EvaluationOrder.cs
+//
+// Author:
+// Marek Sieradzki (marek.sieradzki@gmail.com)
+//
+// (C) 2006 Marek Sieradzki
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+using System;
+using System.Xml;
+using Microsoft.Build.BuildEngine;
+using NUnit.Framework;
+
+namespace MonoTests.Microsoft.Build.BuildEngine.Various {
+ [TestFixture]
+ public class EvaluationOrder {
+ private string GetItems (Project proj, string name)
+ {
+ BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
+ string str = String.Empty;
+ if (big == null)
+ return str;
+
+ foreach (BuildItem bi in big) {
+ if (str == String.Empty)
+ str = bi.FinalItemSpec;
+ else
+ str += ";" + bi.FinalItemSpec;
+ }
+
+ return str;
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestOrder1 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <ItemGroup>
+ <Item Include='A' />
+ </ItemGroup>
+
+ <PropertyGroup>
+ <Property>@(Item)</Property>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
+ Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
+ Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestOrder2 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <Property>@(Item)</Property>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Item Include='A' />
+ </ItemGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
+ Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
+ Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
+ }
+
+ [Test]
+ public void TestOrder3 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <Property>A</Property>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Item Include='$(Property)' />
+ </ItemGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
+ Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
+ Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
+ }
+
+ [Test]
+ public void TestOrder4 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <ItemGroup>
+ <Item Include='$(Property)' />
+ </ItemGroup>
+
+ <PropertyGroup>
+ <Property>A</Property>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
+ Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
+ Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestOrder5 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <ItemGroup>
+ <Item Include='$(Property)' />
+ </ItemGroup>
+
+ <PropertyGroup>
+ <Property>A</Property>
+ <Property2>@(Item)</Property2>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
+ Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
+ Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
+ Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].FinalValue, "A4");
+ Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].Value, "A5");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestOrder6 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <ItemGroup>
+ <Item Include='A' />
+ <Item2 Include='$(Property)' />
+ </ItemGroup>
+
+ <PropertyGroup>
+ <Property>@(Item)</Property>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
+ Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
+ Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
+ Assert.AreEqual ("A", GetItems (proj, "Item2"), "A4");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestImportOrder1 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <Property>Test/resources/Import.csproj</Property>
+ </PropertyGroup>
+
+ <Import Project='$(Property)'/>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidProjectFileException),
+ "The required attribute \"Project\" is missing from element <Import>. ")]
+ [Category ("NotWorking")]
+ public void TestImportOrder2 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <Import Project='$(Property)'/>
+
+ <PropertyGroup>
+ <Property>Test/resources/Import.csproj</Property>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
+ }
+
+ [Test]
+ // NOTE: It will try to import "@(Item)" instead of Test/...
+ [ExpectedException (typeof (InvalidProjectFileException))]
+ [Category ("NotWorking")]
+ public void TestImportOrder3 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <ItemGroup>
+ <Item Include='Test/resources/Import.csproj' />
+ </ItemGroup>
+
+ <Import Project='@(Item)'/>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
+ }
+
+ [Test]
+ // NOTE: It will try to import "@(Item)" instead of Test/...
+ [ExpectedException (typeof (InvalidProjectFileException))]
+ [Category ("NotWorking")]
+ public void TestImportOrder4 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <Import Project='@(Item)'/>
+
+ <ItemGroup>
+ <Item Include='Test/resources/Import.csproj' />
+ </ItemGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestImportOrder5 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <ImportedProperty>AnotherValue</ImportedProperty>
+ </PropertyGroup>
+
+ <Import Project='Test/resources/Import.csproj'/>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
+ Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestImportOrder6 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <Import Project='Test/resources/Import.csproj'/>
+
+ <PropertyGroup>
+ <ImportedProperty>AnotherValue</ImportedProperty>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
+ Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestImportOrder7 ()
+ {
+ Engine engine = new Engine (Consts.BinPath);
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <Import Project='Test/resources/Import.csproj'/>
+
+ <PropertyGroup>
+ <ImportedProperty>Another$(ImportedProperty)</ImportedProperty>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+
+ Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
+ Assert.AreEqual ("Another$(ImportedProperty)", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
+ }
+ }
+}