diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2014-02-19 03:23:19 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2014-02-19 03:25:39 +0400 |
commit | d562f82d8f10cf6a76daa038b7f694c9f3e262ad (patch) | |
tree | d97f365faae8069a93cdd1154f807a1748d8a69b /mcs/class/Microsoft.Build.Engine | |
parent | 254954dc09f4d6e4703b03773bb7be327db2e89b (diff) |
[xbuild] Exists should be false for empty values
BXC17802 - xbuild evaluates Exist wrongly when the item group does not exist
Diffstat (limited to 'mcs/class/Microsoft.Build.Engine')
-rw-r--r-- | mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConditionFunctionExpression.cs | 3 | ||||
-rw-r--r-- | mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/BuildChooseTest.cs | 30 |
2 files changed, 33 insertions, 0 deletions
diff --git a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConditionFunctionExpression.cs b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConditionFunctionExpression.cs index 7140e50566d..308211b16fb 100644 --- a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConditionFunctionExpression.cs +++ b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConditionFunctionExpression.cs @@ -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) diff --git a/mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/BuildChooseTest.cs b/mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/BuildChooseTest.cs index 01b2ab3b0d1..3da4b97cbc6 100644 --- a/mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/BuildChooseTest.cs +++ b/mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/BuildChooseTest.cs @@ -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"); + } } } |