diff options
Diffstat (limited to 'mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation')
7 files changed, 1083 insertions, 0 deletions
diff --git a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectCollectionTest.cs b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectCollectionTest.cs new file mode 100644 index 0000000000..700a41663d --- /dev/null +++ b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectCollectionTest.cs @@ -0,0 +1,150 @@ +// +// ProjectCollectionTest.cs +// +// Author: +// Atsushi Enomoto (atsushi@xamarin.com) +// +// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com) +// +// 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.IO; +using System.Linq; +using System.Xml; +using Microsoft.Build.Construction; +using Microsoft.Build.Evaluation; +using NUnit.Framework; +using Microsoft.Build.Execution; + +namespace MonoTests.Microsoft.Build.Evaluation +{ + [TestFixture] + public class ProjectCollectionTest + { + [Test] + public void GlobalProperties () + { + var g = ProjectCollection.GlobalProjectCollection; + Assert.AreEqual (0, g.GlobalProperties.Count, "#1"); + Assert.IsTrue (g.GlobalProperties.IsReadOnly, "#2"); + } + + [Test] + public void DefaultToolsVersion () + { + var pc = ProjectCollection.GlobalProjectCollection; + Assert.AreEqual (pc.Toolsets.First ().ToolsVersion, pc.DefaultToolsVersion, "#1"); + } + + [Test] + public void Toolsets () + { + var pc = ProjectCollection.GlobalProjectCollection; + Assert.IsNotNull (pc.Toolsets, "#1-1"); + Assert.IsTrue (pc.Toolsets.Any (), "#1-2"); + pc = new ProjectCollection (); + Assert.IsNotNull (pc.Toolsets, "#2-1"); + Assert.IsTrue (pc.Toolsets.Any (), "#2-2"); + } + + [Test] + public void BuildDoesNotIncreaseCollectionContent () + { + string empty_project_xml = "<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (empty_project_xml)); + var root = ProjectRootElement.Create (xml); + var coll = new ProjectCollection (); + var inst = new ProjectInstance (root, null, null, coll); + root.FullPath = "ProjectCollectionTest.BuildDoesNotIncreaseCollectionContent.proj"; + Assert.AreEqual (0, coll.Count, "#1"); + inst.Build (); + Assert.AreEqual (0, coll.Count, "#2"); + } + + [Test] + public void GetLoadedProjectsWithoutFullPath () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + string path = Path.GetFullPath ("foo.xml"); + var pc = new ProjectCollection (); + + pc.LoadProject (XmlReader.Create (new StringReader (project_xml), null, path)); + Assert.AreEqual (0, pc.GetLoadedProjects (path).Count, "#1"); // huh? + Assert.AreEqual (0, pc.LoadedProjects.Count, "#1.1"); + + new Project (root, null, null, pc); + Assert.AreEqual (0, pc.GetLoadedProjects (path).Count, "#2"); // huh? + } + + [Test] + public void GetLoadedProjectsSuccess () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + string path = Path.GetFullPath ("foo.xml"); + var pc = new ProjectCollection (); + + var proj = new Project (root, null, null, pc); + // this order also matters for test; It sets FullPath after Project.ctor(), and should still work. + root.FullPath = "foo.xml"; + + Assert.AreEqual (1, pc.GetLoadedProjects (path).Count, "#1"); // wow ok... + Assert.AreEqual (proj, pc.GetLoadedProjects (path).First (), "#2"); + } + + [Test] + public void GetLoadedProjectsSuccess2 () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + string path = Path.GetFullPath ("GetLoadedProjectsSuccess2.xml"); + var pc = new ProjectCollection (); + + using (var fs = File.CreateText (path)) + fs.Write (project_xml); + try { + var proj = pc.LoadProject (path); + + Assert.AreEqual (1, pc.GetLoadedProjects (path).Count, "#1"); // ok... LoadProject (with filename) adds it to the collection. + Assert.AreEqual (proj, pc.GetLoadedProjects (path).First (), "#2"); + } finally { + File.Delete (path); + } + } + + [Test] + public void GetLoadedProjectsForProjectInstance () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + string path = Path.GetFullPath ("foo.xml"); + var pc = new ProjectCollection (); + root.FullPath = "foo.xml"; + + new ProjectInstance (root, null, null, pc); + Assert.AreEqual (0, pc.GetLoadedProjects (path).Count, "#1"); // so, ProjectInstance does not actually load Project... + } + } +} + diff --git a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectItemDefinitionTest.cs b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectItemDefinitionTest.cs new file mode 100644 index 0000000000..cd86873c84 --- /dev/null +++ b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectItemDefinitionTest.cs @@ -0,0 +1,104 @@ +// +// ProjectItemDefinitionTest.cs +// +// Author: +// Atsushi Enomoto (atsushi@xamarin.com) +// +// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com) +// +// 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.IO; +using System.Linq; +using System.Xml; +using Microsoft.Build.Construction; +using Microsoft.Build.Evaluation; +using Microsoft.Build.Execution; +using NUnit.Framework; +using System.Collections.Generic; + +namespace MonoTests.Microsoft.Build.Evaluation +{ + [TestFixture] + public class ProjectItemDefinitionTest + { + [Test] + public void Properties () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <ItemDefinitionGroup> + <Foo> + <prop1>value1</prop1> + <prop2>value1</prop2> + </Foo> + <!-- This one is merged into existing Foo definition above. --> + <Foo> + <prop1>valueX1</prop1><!-- this one overrides value1. --> + <prop3>value3</prop3> + </Foo> + </ItemDefinitionGroup> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + Assert.AreEqual (1, proj.ItemDefinitions.Count, "#1"); // Foo + var def = proj.ItemDefinitions ["Foo"]; + Assert.AreEqual ("Foo", def.ItemType, "#1x"); + Assert.AreEqual (3, def.MetadataCount, "#2"); + var md1 = def.Metadata.First (m => m.Name == "prop1"); + Assert.AreEqual ("Foo", md1.ItemType, "#2x"); + Assert.AreEqual ("valueX1", md1.UnevaluatedValue, "#3"); + // FIXME: enable it once we implemented it. + //Assert.AreEqual ("valueX1", md1.EvaluatedValue, "#4"); + Assert.IsNotNull (md1.Predecessor, "#5"); + Assert.AreEqual ("value1", md1.Predecessor.UnevaluatedValue, "#6"); + // FIXME: enable it once we implemented it. + //Assert.AreEqual ("value1", md1.Predecessor.EvaluatedValue, "#7"); + } + + [Test] + public void Condition () + { + string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <ItemDefinitionGroup> + <I Condition='{0}'> + <DefinedMetadata>X</DefinedMetadata> + </I> + </ItemDefinitionGroup> + <ItemGroup> + <I Include='foo' /> + </ItemGroup> +</Project>"; + var reader = XmlReader.Create (new StringReader (string.Format (xml, "True"))); + var root = ProjectRootElement.Create (reader); + var proj = new Project (root); + var i = proj.GetItems ("I").First (); + Assert.AreEqual ("X", i.GetMetadataValue ("DefinedMetadata"), "#1"); + + reader = XmlReader.Create (new StringReader (string.Format (xml, "False"))); + root = ProjectRootElement.Create (reader); + proj = new Project (root); + i = proj.GetItems ("I").First (); + Assert.AreEqual (string.Empty, i.GetMetadataValue ("DefinedMetadata"), "#2"); + } + } +} + diff --git a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectItemTest.cs b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectItemTest.cs new file mode 100644 index 0000000000..61973b7ceb --- /dev/null +++ b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectItemTest.cs @@ -0,0 +1,212 @@ +// +// ProjectItemTest.cs +// +// Author: +// Atsushi Enomoto (atsushi@xamarin.com) +// +// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com) +// +// 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.IO; +using System.Linq; +using System.Xml; +using Microsoft.Build.Construction; +using Microsoft.Build.Evaluation; +using Microsoft.Build.Execution; +using NUnit.Framework; +using System.Collections.Generic; + +namespace MonoTests.Microsoft.Build.Evaluation +{ + [TestFixture] + public class ProjectItemTest + { + [Test] + public void SetUnevaluatedInclude () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <ItemGroup> + <Foo Include='foo/bar.txt' /> + </ItemGroup> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + Assert.AreEqual (1, root.ItemGroups.Count, "#1"); + var g = root.ItemGroups.First (); + Assert.AreEqual (1, g.Items.Count, "#2"); + var xitem = g.Items.First (); + var proj = new Project (root); + var item = proj.ItemsIgnoringCondition.First (); + string inc = "foo/bar.txt"; + Assert.AreEqual (inc, xitem.Include, "#3"); + Assert.AreEqual (inc, item.UnevaluatedInclude, "#4"); + string inc2 = "foo/bar.ext.txt"; + item.UnevaluatedInclude = inc2; + Assert.AreEqual (inc2, xitem.Include, "#5"); + Assert.AreEqual (inc2, item.UnevaluatedInclude, "#6"); + } + + void SetupTemporaryDirectoriesAndFiles () + { + Directory.CreateDirectory ("Test/ProjectItemTestTemporary"); + Directory.CreateDirectory ("Test/ProjectItemTestTemporary/parent"); + Directory.CreateDirectory ("Test/ProjectItemTestTemporary/parent/dir1"); + Directory.CreateDirectory ("Test/ProjectItemTestTemporary/parent/dir2"); + File.CreateText ("Test/ProjectItemTestTemporary/x.cs").Close (); + File.CreateText ("Test/ProjectItemTestTemporary/parent/dir1/a.cs").Close (); + File.CreateText ("Test/ProjectItemTestTemporary/parent/dir1/a1.cs").Close (); + File.CreateText ("Test/ProjectItemTestTemporary/parent/dir1/b.cs").Close (); + File.CreateText ("Test/ProjectItemTestTemporary/parent/dir2/a2.cs").Close (); + File.CreateText ("Test/ProjectItemTestTemporary/parent/dir2/a.cs").Close (); + File.CreateText ("Test/ProjectItemTestTemporary/parent/dir2/b.cs").Close (); + } + + void CleanupTemporaryDirectories () + { + Directory.Delete ("Test/ProjectItemTestTemporary", true); + } + + [Test] + public void WildcardExpansion () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <ItemGroup> + <Foo Include='Test/ProjectItemTestTemporary/parent/dir*/a*.cs;Test/ProjectItemTestTemporary/x.cs' /> + </ItemGroup> +</Project>"; + try { + SetupTemporaryDirectoriesAndFiles (); + WildcardExpansionCommon (project_xml, false); + } finally { + CleanupTemporaryDirectories (); + } + } + + [Test] + public void WildcardExpansionRecursive () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <ItemGroup> + <Foo Include='Test/ProjectItemTestTemporary/parent/**/a*.cs;Test/ProjectItemTestTemporary/x.cs' /> + </ItemGroup> +</Project>"; + try { + SetupTemporaryDirectoriesAndFiles (); + WildcardExpansionCommon (project_xml, true); + } finally { + CleanupTemporaryDirectories (); + } + } + + void WildcardExpansionCommon (string xmlString, bool hasRecursiveDir) + { + char sep = Path.DirectorySeparatorChar; + var xml = XmlReader.Create (new StringReader (xmlString)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + var xitem = proj.Xml.Items.First (); + // sort is needed because they are only sorted by ItemType. + var items = proj.Items.OrderBy (p => p.EvaluatedInclude).ToArray (); + Assert.AreEqual (5, items.Length, "#1"); + Assert.AreEqual (string.Format ("Test/ProjectItemTestTemporary/parent/dir1{0}a.cs", Path.DirectorySeparatorChar), items [0].EvaluatedInclude, "#2"); + Assert.AreEqual ("a", items [0].GetMetadataValue ("Filename"), "#3"); + if (hasRecursiveDir) + Assert.AreEqual ("dir1" + sep, items [0].GetMetadataValue ("RecursiveDir"), "#3.2"); + Assert.AreEqual (string.Format ("Test/ProjectItemTestTemporary/parent/dir1{0}a1.cs", Path.DirectorySeparatorChar), items [1].EvaluatedInclude, "#4"); + Assert.AreEqual ("a1", items [1].GetMetadataValue ("Filename"), "#5"); + if (hasRecursiveDir) + Assert.AreEqual ("dir1" + sep, items [1].GetMetadataValue ("RecursiveDir"), "#5.2"); + Assert.AreEqual (string.Format ("Test/ProjectItemTestTemporary/parent/dir2{0}a.cs", Path.DirectorySeparatorChar), items [2].EvaluatedInclude, "#6"); + Assert.AreEqual ("a", items [2].GetMetadataValue ("Filename"), "#7"); + if (hasRecursiveDir) + Assert.AreEqual ("dir2" + sep, items [2].GetMetadataValue ("RecursiveDir"), "#7.2"); + Assert.AreEqual (string.Format ("Test/ProjectItemTestTemporary/parent/dir2{0}a2.cs", Path.DirectorySeparatorChar), items [3].EvaluatedInclude, "#8"); + Assert.AreEqual ("a2", items [3].GetMetadataValue ("Filename"), "#9"); + if (hasRecursiveDir) + Assert.AreEqual ("dir2" + sep, items [3].GetMetadataValue ("RecursiveDir"), "#9.2"); + Assert.AreEqual ("Test/ProjectItemTestTemporary/x.cs", items [4].EvaluatedInclude, "#10"); + for (int i = 0; i < items.Length; i++) + Assert.AreEqual (xitem, items [i].Xml, "#11:" + i); + } + + [Test] + public void Metadata () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <ItemDefinitionGroup> + <Foo> + <prop1>value1</prop1> + </Foo> + </ItemDefinitionGroup> + <ItemGroup> + <Foo Include='foo/bar.txt'> + <prop1>valueX1</prop1> + </Foo> + </ItemGroup> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + Assert.AreEqual (1, root.ItemGroups.Count, "#1"); + var g = root.ItemGroups.First (); + Assert.AreEqual (1, g.Items.Count, "#2"); + var proj = new Project (root); + var item = proj.ItemsIgnoringCondition.First (); + var meta = item.GetMetadata ("prop1"); + Assert.IsNotNull (meta, "#3"); + Assert.AreEqual ("valueX1", meta.UnevaluatedValue, "#4"); + Assert.IsNotNull (meta.Predecessor, "#5"); + Assert.AreEqual ("value1", meta.Predecessor.UnevaluatedValue, "#6"); + + // Well-known metadata don't show up via GetMetadata(), but does show up via GetMetadataValue(). + Assert.AreEqual (null, item.GetMetadata ("Filename"), "#7"); + Assert.AreEqual ("bar", item.GetMetadataValue ("Filename"), "#8"); + } + + [Test] + public void ExpandPropertyThenTrim () + { + string test = @"A +B +C + "; + string project_xml = string.Format (@"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <Test>{0}</Test> + <Test2>$(TEST)</Test2> + </PropertyGroup> + <ItemGroup> + <X Include='$(TEST)' /> + <X2 Include='$(TEST)z' /> + </ItemGroup> +</Project>", test); + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + root.FullPath = "ProjectItemTest.ExpandPropertyThenTrim.proj"; + var proj = new ProjectInstance (root); + Assert.AreEqual (test, proj.GetPropertyValue ("TEST"), "#1"); + Assert.AreEqual (test, proj.GetPropertyValue ("TEST2"), "#2"); + Assert.AreEqual (test.Trim (), proj.GetItems ("X").First ().EvaluatedInclude, "#3"); + Assert.AreEqual (test + "z", proj.GetItems ("X2").First ().EvaluatedInclude, "#4"); + } + } +} + diff --git a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectPropertyTest.cs b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectPropertyTest.cs new file mode 100644 index 0000000000..9c89ef09f6 --- /dev/null +++ b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectPropertyTest.cs @@ -0,0 +1,130 @@ +// +// ProjectPropertyTest.cs +// +// Author: +// Atsushi Enomoto (atsushi@xamarin.com) +// +// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com) +// +// 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.IO; +using System.Linq; +using System.Xml; +using Microsoft.Build.Construction; +using Microsoft.Build.Evaluation; +using Microsoft.Build.Execution; +using NUnit.Framework; +using System.Collections.Generic; + +namespace MonoTests.Microsoft.Build.Evaluation +{ + [TestFixture] + public class ProjectPropertyTest + { + [Test] + public void SetUnevaluatedValueOverwritesElementValue () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <Foo>Bar</Foo> + <Item/> + <X>1</X> + <X>2</X> + <PATH>overriden</PATH> + </PropertyGroup> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var pe = root.Properties.First (); + Assert.AreEqual ("Bar", pe.Value, "#1"); + var proj = new Project (root); + var prop = proj.Properties.First (p => p.Name == "Foo"); + Assert.AreEqual ("Bar", prop.UnevaluatedValue, "#2"); + prop.UnevaluatedValue = "x"; + Assert.AreEqual ("x", pe.Value, "#3"); + + prop = proj.Properties.First (p => p.Name == "X"); + Assert.AreEqual ("2", prop.UnevaluatedValue, "#4"); + Assert.IsNotNull (prop.Predecessor, "#5"); + Assert.AreEqual ("1", prop.Predecessor.UnevaluatedValue, "#6"); + + // environment property could also be Predecessor (and removed...maybe. + // I could reproduce only NRE = .NET bug with environment property so far.) + prop = proj.Properties.First (p => p.Name == "PATH"); + Assert.AreEqual ("overriden", prop.UnevaluatedValue, "#7"); + Assert.IsNotNull (prop.Predecessor, "#8"); + } + + [Test] + [ExpectedException (typeof(InvalidOperationException))] + public void UpdateGlobalPropertyValue () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var props = new Dictionary<string, string> (); + props.Add ("GP", "GV"); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root, props, null); + var pe = proj.Properties.First (p => p.IsGlobalProperty); + pe.UnevaluatedValue = "UPDATED"; + } + + [Test] + [ExpectedException (typeof (InvalidOperationException))] + public void UpdateEnvironmentPropertyValue () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + var pe = proj.Properties.First (p => p.IsEnvironmentProperty); + pe.UnevaluatedValue = "UPDATED"; + } + + [Test] + public void DeepReferences () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <A>1</A> + <B>$(A)+1</B> + <C>$(B)+2</C> + </PropertyGroup> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + Assert.AreEqual ("1+1+2", new Project (root).GetProperty ("C").EvaluatedValue, "#1"); + Assert.AreEqual ("1+1+2", new ProjectInstance (root).GetProperty ("C").EvaluatedValue, "#1"); + } + + [Test] + public void PlatformPropertyEmptyByDefault () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + Assert.IsNull (proj.GetProperty ("PLATFORM"), "#1"); + } + } +} + diff --git a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectTest.cs b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectTest.cs new file mode 100644 index 0000000000..4ea4551816 --- /dev/null +++ b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ProjectTest.cs @@ -0,0 +1,253 @@ +// +// ProjectTest.cs +// +// Author: +// Atsushi Enomoto (atsushi@xamarin.com) +// +// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com) +// +// 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.IO; +using System.Linq; +using System.Xml; +using Microsoft.Build.Construction; +using Microsoft.Build.Evaluation; +using NUnit.Framework; +using Microsoft.Build.Exceptions; +using Microsoft.Build.Logging; +using Microsoft.Build.Framework; + +namespace MonoTests.Microsoft.Build.Evaluation +{ + [TestFixture] + public class ProjectTest + { + [Test] + public void EscapeDoesWTF () + { + string value_xml = "What are 'ESCAPE' & \"EVALUATE\" ? $ # % ^"; + string value = "What are 'ESCAPE' & \"EVALUATE\" ? $ # % ^"; + string escaped = "What are %27ESCAPE%27 & \"EVALUATE\" %3f %24 # %25 ^"; + string xml = string.Format (@"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <Foo>{0}</Foo> + <Baz>$(FOO)</Baz> + </PropertyGroup> +</Project>", value_xml); + var path = "file://localhost/foo.xml"; + var reader = XmlReader.Create (new StringReader (xml), null, path); + var root = ProjectRootElement.Create (reader); + var proj = new Project (root); + var prop = proj.Properties.First (p => p.Name == "Foo"); + Assert.AreEqual (value, prop.UnevaluatedValue, "#1"); + Assert.AreEqual (value, prop.EvaluatedValue, "#2"); + // eh? + Assert.AreEqual (value, Project.GetPropertyValueEscaped (prop), "#3"); + prop = proj.Properties.First (p => p.Name == "Baz"); + Assert.AreEqual ("$(FOO)", prop.UnevaluatedValue, "#4"); + Assert.AreEqual (value, prop.EvaluatedValue, "#5"); + // eh? + Assert.AreEqual (value, Project.GetPropertyValueEscaped (prop), "#6"); + + // OK you are fine. + Assert.AreEqual (escaped, ProjectCollection.Escape (value), "#7"); + } + + [Test] + public void FullPath () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml), null, "file://localhost/foo.xml"); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + proj.FullPath = "ABC"; + Assert.IsTrue (proj.FullPath.EndsWith (Path.DirectorySeparatorChar + "ABC"), "#1"); + Assert.AreEqual (root.FullPath, proj.FullPath, "#2"); + } + + [Test] + public void BuildEmptyProject () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml), null, "file://localhost/foo.xml"); + var root = ProjectRootElement.Create (xml); + root.FullPath = "ProjectTest.BuildEmptyProject.proj"; + + // This seems to do nothing and still returns true + Assert.IsTrue (new Project (root) { FullPath = "ProjectTest.BuildEmptyProject.1.proj" }.Build (), "#1"); + // This seems to fail to find the appropriate target + Assert.IsFalse (new Project (root) { FullPath = "ProjectTest.BuildEmptyProject.2.proj" }.Build ("Build", null), "#2"); + // Thus, this tries to build all the targets (empty) and no one failed, so returns true(!) + Assert.IsTrue (new Project (root) { FullPath = "ProjectTest.BuildEmptyProject.3.proj" }.Build (new string [0], null), "#3"); + // Actially null "targets" is accepted and returns true(!!) + Assert.IsTrue (new Project (root) { FullPath = "ProjectTest.BuildEmptyProject.4.proj" }.Build ((string []) null, null), "#4"); + // matching seems to be blindly done, null string also results in true(!!) + Assert.IsTrue (new Project (root) { FullPath = "ProjectTest.BuildEmptyProject.5.proj" }.Build ((string) null, null), "#5"); + } + + [Test] + [ExpectedException (typeof (InvalidProjectFileException))] + public void LoadInvalidProjectForBadCondition () + { + string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <Foo>What are 'ESCAPE' & ""EVALUATE"" ? $ # % ^</Foo> + <!-- Note that this contains invalid Condition expression, yet ProjectElement.Create() does NOT fail. --> + <Baz Condition=""$(Void)=="">$(FOO)</Baz> + </PropertyGroup> +</Project>"; + var reader = XmlReader.Create (new StringReader (xml)); + var root = ProjectRootElement.Create (reader); + new Project (root); + } + + [Test] + public void ExpandString () + { + string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <Foo>What are 'ESCAPE' & ""EVALUATE"" ? $ # % ^</Foo> + <Bar>y</Bar> + <Baz Condition=""$(Void)==''"">$(FOO)</Baz> + </PropertyGroup> +</Project>"; + var reader = XmlReader.Create (new StringReader (xml)); + var root = ProjectRootElement.Create (reader); + var proj = new Project (root); + root.FullPath = "ProjectTest.ExpandString.proj"; + Assert.AreEqual ("xyz", proj.ExpandString ("x$(BAR)z"), "#1"); + Assert.AreEqual ("x$(BARz", proj.ExpandString ("x$(BARz"), "#2"); // incomplete + Assert.AreEqual ("xz", proj.ExpandString ("x@(BAR)z"), "#3"); // not an item + } + + [Test] + public void BuildCSharpTargetGetFrameworkPaths () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <Import Project='$(MSBuildToolsPath)\Microsoft.CSharp.targets' /> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + root.FullPath = "ProjectTest.BuildCSharpTargetGetFrameworkPaths.proj"; + Assert.IsTrue (proj.Build ("GetFrameworkPaths", new ILogger [] {/*new ConsoleLogger ()*/})); + } + + [Test] + public void BuildCSharpTargetBuild () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <AssemblyName>Foo</AssemblyName> + </PropertyGroup> + <Import Project='$(MSBuildToolsPath)\Microsoft.CSharp.targets' /> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + root.FullPath = "ProjectTest.BuildCSharpTargetBuild.proj"; + var proj = new Project (root, null, "4.0"); + Assert.IsFalse (proj.Build ("Build", new ILogger [] {/*new ConsoleLogger (LoggerVerbosity.Diagnostic)*/})); // missing mandatory properties + } + + [Test] + public void EvaluateItemConditionThenIgnored () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <P></P> + </PropertyGroup> + <ItemGroup> + <Foo Condition='' Include='x' /> + <Bar Include='$(P)' /> + <Baz Include='z' /> + </ItemGroup> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + // note that Foo is ignored BUT Bar is NOT ignored. + Assert.AreEqual (2, proj.ItemsIgnoringCondition.Count, "#1"); + Assert.IsNotNull ("Bar", proj.ItemsIgnoringCondition.First ().ItemType, "#2"); + Assert.IsNotNull ("Baz", proj.ItemsIgnoringCondition.Last ().ItemType, "#3"); + } + + [Test] + public void EvaluateSamePropertiesInOrder () + { + // used in Microsoft.Common.targets + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <BaseIntermediateOutputPath Condition=""'$(BaseIntermediateOutputPath)' == ''"">obj\</BaseIntermediateOutputPath> + </PropertyGroup> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + Assert.AreEqual ("obj\\", proj.GetPropertyValue ("BaseIntermediateOutputPath"), "#1"); + } + + [Test] + public void DirtyMarking () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + Assert.IsFalse (proj.IsDirty, "#1"); + proj.MarkDirty (); + Assert.IsTrue (proj.IsDirty, "#2"); + } + + [Test] + public void DirtyMarking2 () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root); + proj.DisableMarkDirty = true; + proj.MarkDirty (); + Assert.IsFalse (proj.IsDirty, "#1"); // not rejected, just ignored. + proj.DisableMarkDirty = false; + Assert.IsFalse (proj.IsDirty, "#2"); // not like status pending + proj.MarkDirty (); + Assert.IsTrue (proj.IsDirty, "#3"); + } + + [Test] + public void CreateProjectInstance () + { + string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <AssemblyName>Foo</AssemblyName> + </PropertyGroup> + <Import Project='$(MSBuildToolsPath)\Microsoft.CSharp.targets' /> +</Project>"; + var xml = XmlReader.Create (new StringReader (project_xml)); + var root = ProjectRootElement.Create (xml); + var proj = new Project (root, null, "4.0"); + var inst = proj.CreateProjectInstance (); + Assert.AreEqual ("4.0", inst.ToolsVersion, "#1"); + } + } +} + diff --git a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ResolvedImportTest.cs b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ResolvedImportTest.cs new file mode 100644 index 0000000000..9c4359ee7a --- /dev/null +++ b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ResolvedImportTest.cs @@ -0,0 +1,181 @@ +// +// ResolvedImportTest.cs +// +// Author: +// Atsushi Enomoto (atsushi@xamarin.com) +// +// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com) +// +// 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.IO; +using System.Linq; +using System.Xml; +using Microsoft.Build.Construction; +using Microsoft.Build.Evaluation; +using NUnit.Framework; +using Microsoft.Build.Exceptions; +using Microsoft.Build.Framework; +using Microsoft.Build.Execution; + +namespace MonoTests.Microsoft.Build.Evaluation +{ + [TestFixture] + public class ResolvedImportTest + { + const string temp_file_name = "test_imported.proj"; + + [Test] + public void SimpleImportAndSemanticValues () + { + string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <Import Project='test_imported.proj' /> +</Project>"; + string imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <A>x</A> + <B>y</B> + </PropertyGroup> + <ItemGroup> + <X Include=""included.txt"" /> + </ItemGroup> +</Project>"; + using (var ts = File.CreateText (temp_file_name)) + ts.Write (imported); + try { + var reader = XmlReader.Create (new StringReader (xml)); + var root = ProjectRootElement.Create (reader); + Assert.AreEqual (temp_file_name, root.Imports.First ().Project, "#1"); + var proj = new Project (root); + var prop = proj.GetProperty ("A"); + Assert.IsNotNull (prop, "#2"); + Assert.IsTrue (prop.IsImported, "#3"); + var item = proj.GetItems ("X").FirstOrDefault (); + Assert.IsNotNull (item, "#4"); + Assert.AreEqual ("included.txt", item.EvaluatedInclude, "#5"); + } finally { + File.Delete (temp_file_name); + } + } + + string import_overrides_test_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <A>X</A> + </PropertyGroup> + <Import Condition=""{0}"" Project='test_imported.proj' /> + <PropertyGroup> + <B>Y</B> + </PropertyGroup> +</Project>"; + string import_overrides_test_imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <C Condition='$(A)==x'>c</C> + <A>a</A> + <B>b</B> + </PropertyGroup> + <ItemGroup> + <X Include=""included.txt"" /> + </ItemGroup> +</Project>"; + + void ImportAndPropertyOverrides (string label, string condition, string valueA, string valueB, string valueAPredecessor, bool existsC) + { + using (var ts = File.CreateText (temp_file_name)) + ts.Write (import_overrides_test_imported); + try { + string xml = string.Format (import_overrides_test_xml, condition); + var reader = XmlReader.Create (new StringReader (xml)); + var root = ProjectRootElement.Create (reader); + var proj = new Project (root); + var a = proj.GetProperty ("A"); + Assert.IsNotNull (a, label + "#2"); + Assert.AreEqual (valueA, a.EvaluatedValue, label + "#3"); + if (valueAPredecessor == null) + Assert.IsNull (a.Predecessor, label + "#3.1"); + else { + Assert.IsNotNull (a.Predecessor, label + "#3.2"); + Assert.AreEqual (valueAPredecessor, a.Predecessor.EvaluatedValue, label + "#3.3"); + } + var b = proj.GetProperty ("B"); + Assert.IsNotNull (b, label + "#4"); + Assert.AreEqual (valueB, b.EvaluatedValue, label + "#5"); + var c = proj.GetProperty ("C"); // yes it can be retrieved. + if (existsC) { + Assert.IsNotNull (c, label + "#6"); + Assert.AreEqual ("c", c.EvaluatedValue, label + "#7"); + } + else + Assert.IsNull (c, label + "#8"); + } finally { + File.Delete (temp_file_name); + } + } + + [Test] + public void ImportAndPropertyOverrides () + { + ImportAndPropertyOverrides ("[1]", "'True'", "a", "Y", "X", true); + ImportAndPropertyOverrides ("[2]", "$(A)=='X'", "a", "Y", "X", true); // evaluated as true + ImportAndPropertyOverrides ("[3]", "$(B)=='Y'", "X", "Y", null, false); // evaluated as false + ImportAndPropertyOverrides ("[4]", "$(B)=='b'", "X", "Y", null, false); // of course not evaluated with imported value + } + + // FIXME: + // Looks like $(MSBuildThisFile) is available only within property value, not via .NET MSBuild API. + // Right now our variable is added as a Reserved property, but we will have to hide it. + // + [Test] + public void EvaluateMSBuildThisFileProperty () + { + string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <A>$(MSBuildThisFile)</A> + </PropertyGroup> + <Import Project='test_imported.proj' /> +</Project>"; + string imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> + <PropertyGroup> + <B>$(MSBuildThisFile)</B> + </PropertyGroup> +</Project>"; + using (var ts = File.CreateText (temp_file_name)) + ts.Write (imported); + try { + var reader = XmlReader.Create (new StringReader (xml)); + var root = ProjectRootElement.Create (reader); + var proj = new Project (root); + var a = proj.GetProperty ("A"); + Assert.AreEqual (string.Empty, a.EvaluatedValue, "#1"); + var b = proj.GetProperty ("B"); + Assert.AreEqual (temp_file_name, b.EvaluatedValue, "#2"); + + var pi = new ProjectInstance (root); + var ai = pi.GetProperty ("A"); + Assert.AreEqual (string.Empty, ai.EvaluatedValue, "#3"); + var bi = pi.GetProperty ("B"); + Assert.AreEqual (temp_file_name, bi.EvaluatedValue, "#4"); + } finally { + File.Delete (temp_file_name); + } + } + } +} + diff --git a/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ToolsetTest.cs b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ToolsetTest.cs new file mode 100644 index 0000000000..ac4e2d6610 --- /dev/null +++ b/mcs/class/Microsoft.Build/Test/Microsoft.Build.Evaluation/ToolsetTest.cs @@ -0,0 +1,53 @@ +// +// ToolSetTest.cs +// +// Author: +// Atsushi Enomoto (atsushi@xamarin.com) +// +// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com) +// +// 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 Microsoft.Build.Evaluation; +using NUnit.Framework; + +namespace MonoTests.Microsoft.Build.Evaluation +{ + [TestFixture] + public class ToolsetTest + { + [Test] + public void Constructor () + { + var ts = new Toolset ("4.3", "c:\\", ProjectCollection.GlobalProjectCollection, null); + Assert.IsNotNull (ts.Properties, "#1"); + Assert.AreEqual (0, ts.Properties.Count, "#2"); +#if NET_4_5 + Assert.IsNull (ts.DefaultSubToolsetVersion, "#3"); + Assert.IsNotNull (ts.SubToolsets, "#4"); + Assert.AreEqual (0, ts.SubToolsets.Count, "#5"); +#endif + Assert.AreEqual ("c:\\", ts.ToolsPath, "#6"); + Assert.AreEqual ("4.3", ts.ToolsVersion, "#7"); + } + } +} + |