5 using Microsoft.Build.Construction;
6 using Microsoft.Build.Evaluation;
8 using Microsoft.Build.Exceptions;
9 using Microsoft.Build.Logging;
10 using Microsoft.Build.Framework;
12 namespace MonoTests.Microsoft.Build.Evaluation
15 public class ProjectTest
18 [Category ("NotWorking")]
19 public void EscapeDoesWTF ()
21 string value = "What are 'ESCAPE' & \"EVALUATE\" ? $ # % ^";
22 string escaped_by_collection = "What are %27ESCAPE%27 & \"EVALUATE\" %3f %24 # %25 ^";
23 string xml = string.Format (@"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
29 var path = "file://localhost/foo.xml";
30 var reader = XmlReader.Create (new StringReader (xml), null, path);
31 var root = ProjectRootElement.Create (xml);
32 var proj = new Project (root);
33 var prop = proj.Properties.First (p => p.Name == "Foo");
34 Assert.AreEqual (value, prop.UnevaluatedValue, "#1");
35 Assert.AreEqual (value, prop.EvaluatedValue, "#2");
37 Assert.AreEqual (value, Project.GetPropertyValueEscaped (prop), "#3");
38 prop = proj.Properties.First (p => p.Name == "Baz");
39 Assert.AreEqual ("$(FOO)", prop.UnevaluatedValue, "#4");
40 Assert.AreEqual (value, prop.EvaluatedValue, "#5");
42 Assert.AreEqual (value, Project.GetPropertyValueEscaped (prop), "#6");
45 Assert.AreEqual (escaped_by_collection, ProjectCollection.Escape (value), "#7");
49 public void FullPath ()
51 string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
52 var xml = XmlReader.Create (new StringReader (project_xml), null, "file://localhost/foo.xml");
53 var root = ProjectRootElement.Create (xml);
54 var proj = new Project (root);
55 proj.FullPath = "ABC";
56 Assert.IsTrue (proj.FullPath.EndsWith (Path.DirectorySeparatorChar + "ABC"), "#1");
57 Assert.AreEqual (root.FullPath, proj.FullPath, "#2");
61 public void BuildEmptyProject ()
63 string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
64 var xml = XmlReader.Create (new StringReader (project_xml), null, "file://localhost/foo.xml");
65 var root = ProjectRootElement.Create (xml);
67 // This seems to do nothing and still returns true
68 Assert.IsTrue (new Project (root).Build (), "#1");
69 // This seems to fail to find the appropriate target
70 Assert.IsFalse (new Project (root).Build ("Build", null), "#2");
71 // Thus, this tries to build all the targets (empty) and no one failed, so returns true(!)
72 Assert.IsTrue (new Project (root).Build (new string [0], null), "#3");
73 // Actially null "targets" is accepted and returns true(!!)
74 Assert.IsTrue (new Project (root).Build ((string []) null, null), "#4");
75 // matching seems to be blindly done, null string also results in true(!!)
76 Assert.IsTrue (new Project (root).Build ((string) null, null), "#5");
80 [ExpectedException (typeof (InvalidProjectFileException))]
81 [Category ("NotWorking")]
82 public void LoadInvalidProjectForBadCondition ()
84 string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
86 <Foo>What are 'ESCAPE' & ""EVALUATE"" ? $ # % ^</Foo>
87 <!-- Note that this contains invalid Condition expression, yet ProjectElement.Create() does NOT fail. -->
88 <Baz Condition=""$(Void)=="">$(FOO)</Baz>
91 var path = "file://localhost/foo.xml";
92 var reader = XmlReader.Create (new StringReader (xml), null, path);
93 var root = ProjectRootElement.Create (reader);
98 [Category ("NotWorking")]
99 public void ExpandString ()
101 string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
103 <Foo>What are 'ESCAPE' & ""EVALUATE"" ? $ # % ^</Foo>
105 <Baz Condition=""$(Void)==''"">$(FOO)</Baz>
108 var path = "file://localhost/foo.xml";
109 var reader = XmlReader.Create (new StringReader (xml), null, path);
110 var root = ProjectRootElement.Create (reader);
111 var proj = new Project (root);
112 Assert.AreEqual ("xyz", proj.ExpandString ("x$(BAR)z"), "#1");
113 Assert.AreEqual ("x$(BARz", proj.ExpandString ("x$(BARz"), "#2"); // incomplete
114 Assert.AreEqual ("xz", proj.ExpandString ("x@(BAR)z"), "#3"); // not an item
118 [Category ("NotWorking")]
119 public void BuildCSharpTargetGetFrameworkPaths ()
121 string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
122 <Import Project='$(MSBuildToolsPath)\Microsoft.CSharp.targets' />
124 var path = "file://localhost/foo.xml";
125 var xml = XmlReader.Create (new StringReader (project_xml));
126 var root = ProjectRootElement.Create (xml);
127 var proj = new Project (root);
128 Assert.IsTrue (proj.Build ("GetFrameworkPaths", new ILogger [] {new ConsoleLogger ()}));
132 [Category ("NotWorking")]
133 public void BuildCSharpTargetBuild ()
135 string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
136 <Import Project='$(MSBuildToolsPath)\Microsoft.CSharp.targets' />
138 var path = "file://localhost/foo.xml";
139 var xml = XmlReader.Create (new StringReader (project_xml));
140 var root = ProjectRootElement.Create (xml);
141 var proj = new Project (root);
142 Assert.IsFalse (proj.Build ("Build", new ILogger [] {new ConsoleLogger ()})); // missing mandatory properties