Assert.AreEqual (false, engine.OnlyLogCriticalEvents, "A1");
}
+ private static string GetPropValue (BuildPropertyGroup bpg, string name)
+ {
+ foreach (BuildProperty bp in bpg) {
+ if (bp.Name == name) {
+ return bp.FinalValue;
+ }
+ }
+ return String.Empty;
+ }
+
[Test]
public void TestGlobalProperties ()
{
engine = new Engine (binPath);
+ Project project;
Assert.IsNotNull (engine.GlobalProperties, "A1");
Assert.AreEqual (0, engine.GlobalProperties.Count, "A2");
Assert.AreEqual (String.Empty, engine.GlobalProperties.Condition, "A3");
Assert.IsFalse (engine.GlobalProperties.IsImported, "A4");
+
+ engine.GlobalProperties.SetProperty ("GlobalA", "value1");
+ Assert.AreEqual (1, engine.GlobalProperties.Count, "A5");
+ engine.GlobalProperties.SetProperty ("GlobalB", "value1");
+ Assert.AreEqual (2, engine.GlobalProperties.Count, "A6");
+ engine.GlobalProperties.SetProperty ("GlobalA", "value2");
+ Assert.AreEqual (2, engine.GlobalProperties.Count, "A7");
+
+ project = engine.CreateNewProject ();
+ Assert.AreEqual (2, project.GlobalProperties.Count, "A8");
+ project.GlobalProperties.SetProperty ("GlobalC", "value3");
+ Assert.AreEqual (3, project.GlobalProperties.Count, "A9");
+ Assert.AreEqual (2, engine.GlobalProperties.Count, "A10");
+
+ project.GlobalProperties.SetProperty ("GlobalA", "value3");
+ Assert.AreEqual ("value2", GetPropValue(engine.GlobalProperties, "GlobalA"), "A11");
+ engine.GlobalProperties.SetProperty ("GlobalB", "value3");
+ Assert.AreEqual ("value1", GetPropValue(project.GlobalProperties, "GlobalB"), "A12");
+
+ engine.GlobalProperties.SetProperty ("GlobalC", "value4");
+ engine.GlobalProperties.SetProperty ("GlobalD", "value5");
+ Assert.AreEqual (4, engine.GlobalProperties.Count, "A13");
+ Assert.AreEqual (3, project.GlobalProperties.Count, "A14");
+
+ project = new Project (engine);
+ Assert.AreEqual (4, project.GlobalProperties.Count, "A15");
}
}
}
[TestFixture]
public class ProjectTest {
- string binPath;
+ string binPath;
- [SetUp]
- public void SetUp ()
- {
- binPath = "binPath";
- }
+ [SetUp]
+ public void SetUp ()
+ {
+ binPath = "binPath";
+ }
// Clones a project by reloading from original.Xml
private Project CloneProject (Project original)
[Test]
[ExpectedException (typeof (InvalidProjectFileException),
@"The default XML namespace of the project must be the MSBuild XML namespace." +
- " If the project is authored in the MSBuild 2003 format, please add " +
+ " If the project is authored in the MSBuild 2003 format, please add " +
"xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" to the <Project> element. " +
"If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. ")]
public void TestAssignment ()
Project proj;
Project cproj;
string documentString = @"
- <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" DefaultTargets=""Build;Compile"">
- </Project>
- ";
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" DefaultTargets=""Build;Compile"">
+ </Project>
+ ";
engine = new Engine (binPath);
proj = engine.CreateNewProject ();
}
[Test]
- public void TestListProperties ()
+ public void TestProperties ()
{
Engine engine = new Engine (binPath);
Project proj = engine.CreateNewProject ();
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
- <Prop1>value1</Prop1>
+ <Config>debug</Config>
+ <ExpProp>$(Config)-$(Config)</ExpProp>
</PropertyGroup>
</Project>
";
proj.LoadXml (documentString);
- Assert.AreEqual (proj.PropertyGroups.Count, 1, "A1");
+ Assert.AreEqual (1, proj.PropertyGroups.Count, "A1");
+ Assert.AreEqual ("debug", proj.GetEvaluatedProperty ("Config"), "A2");
+ Assert.AreEqual ("debug-debug", proj.GetEvaluatedProperty ("ExpProp"), "A3");
+ }
+
+ // Get all items with a specific name, separated by ;
+ 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]
+ public void TestItems ()
+ {
+ Engine engine = new Engine ();
+ Project proj = engine.CreateNewProject ();
+
+ string documentString = @"
+ <Project>
+ <ItemGroup>
+ <Item0 Include=""A"" />
+ <Item1 Include=""A;B;C"" />
+ <Item2 Include=""@(Item1);A;D"" />
+ <Item3 Include=""@(Item2)"" Exclude=""A"" />
+ <Item4 Include=""@(Item1);Q"" Exclude=""@(Item2)"" />
+ <Item5 Include=""@(Item1)"" Exclude=""@(Item2)"" />
+ <Item6 Include=""@(Item2)"" Exclude=""@(Item1)"" />
+
+ <ItemOrig Include=""A/B.txt;A/C.txt;B/B.zip;B/C.zip"" />
+ <ItemT1 Include=""@(Item1->'%(Identity)')"" />
+ <ItemT2 Include=""@(Item1->'%(Identity)%(Identity)')"" />
+ <ItemT3 Include=""@(Item1->'(-%(Identity)-)')"" />
+ <ItemT4 Include=""@(ItemOrig->'%(Extension)')"" />
+ <ItemT5 Include=""@(ItemOrig->'%(Filename)/%(Extension)')"" />
+ <ItemT6 Include=""@(ItemOrig->'%(RelativeDir)/X/%(Filename)')"" />
+
+ <ItemS1 Include=""@(Item1,'-')"" />
+ <ItemS2 Include=""@(Item1,'xx')"" />
+ <ItemS3 Include=""@(Item1, '-')"" />
+ </ItemGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ Assert.AreEqual ("A", GetItems (proj, "Item0"), "Item0");
+ Assert.AreEqual ("A;B;C", GetItems (proj, "Item1"), "Item1");
+ Assert.AreEqual ("A;B;C;A;D", GetItems (proj, "Item2"), "Item2");
+ Assert.AreEqual ("B;C;D", GetItems (proj, "Item3"), "Item3");
+ Assert.AreEqual ("Q", GetItems (proj, "Item4"), "Item4");
+ Assert.AreEqual ("", GetItems (proj, "Item5"), "Item5");
+ Assert.AreEqual ("D", GetItems (proj, "Item6"), "Item6");
+
+ Assert.AreEqual ("A;B;C", GetItems (proj, "ItemT1"), "ItemT1");
+ Assert.AreEqual ("AA;BB;CC", GetItems (proj, "ItemT2"), "ItemT2");
+ Assert.AreEqual ("(-A-);(-B-);(-C-)", GetItems (proj, "ItemT3"), "ItemT3");
+ Assert.AreEqual (".txt;.txt;.zip;.zip", GetItems (proj, "ItemT4"), "ItemT4");
+ Assert.AreEqual ("B/.txt;C/.txt;B/.zip;C/.zip", GetItems (proj, "ItemT5"), "ItemT5");
+ Assert.AreEqual ("A/X/B;A/X/C;B/X/B;B/X/C", GetItems (proj, "ItemT6"), "ItemT6");
+
+ Assert.AreEqual ("A-B-C", GetItems (proj, "ItemS1"), "ItemS1");
+ Assert.AreEqual ("AxxBxxC", GetItems (proj, "ItemS2"), "ItemS2");
+ // Will fail.
+ Assert.AreEqual ("A-B-C", GetItems (proj, "ItemS3"), "ItemS3");
}
}
}