[xbuild] Exists should be false for empty values
authorMichael Hutchinson <m.j.hutchinson@gmail.com>
Tue, 18 Feb 2014 23:23:19 +0000 (18:23 -0500)
committerMichael Hutchinson <m.j.hutchinson@gmail.com>
Tue, 18 Feb 2014 23:25:39 +0000 (18:25 -0500)
BXC17802 - xbuild evaluates Exist wrongly when the item group does not exist

mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConditionFunctionExpression.cs
mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/BuildChooseTest.cs

index 7140e50566d96e5b110a9e6243912ecfe4c22936..308211b16fbb4a8fe7f80ef948788e6f716ff69e 100644 (file)
@@ -103,6 +103,9 @@ namespace Microsoft.Build.BuildEngine {
                // FIXME imported projects
                static bool Exists (string file, Project context)
                {
+                       if (string.IsNullOrEmpty (file))
+                               return false;
+
                        string directory  = null;
                        
                        if (context.FullFileName != String.Empty)
index 01b2ab3b0d187330045a589338d60d588cf580c1..3da4b97cbc6f453b5035d87f0ca77748009888c0 100644 (file)
@@ -400,5 +400,35 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        
                        Assert.AreEqual ("no", project.GetEvaluatedProperty ("Exists"), "A1");
                }
+
+               [Test]
+               public void EmptyExistsCondition()
+               {
+                       string documentString = @"
+                               <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
+                                       <Choose>
+                                               <When Condition=""Exists('$(UndefinedProperty)')"">
+                                                       <PropertyGroup>
+                                                               <Exists>yes</Exists>
+                                                       </PropertyGroup>
+                                               </When>
+                                               <Otherwise>
+                                                       <PropertyGroup>
+                                                               <Exists>no</Exists>
+                                                       </PropertyGroup>
+                                               </Otherwise>
+                                       </Choose>
+                               </Project>
+                       ";
+
+                       Engine engine = new Engine (Consts.BinPath);
+                       Project project = engine.CreateNewProject ();
+                       //assign a real filename to be used as base path for the Exists
+                       project.FullFileName = typeof (BuildChooseTest).Assembly.Location;
+
+                       project.LoadXml (documentString);
+
+                       Assert.AreEqual ("no", project.GetEvaluatedProperty ("Exists"), "A1");
+               }
        }
 }