[xbuild] Support short-circuiting in conditions.
authorAnkit Jain <radical@corewars.org>
Tue, 25 Jan 2011 23:07:17 +0000 (04:37 +0530)
committerAnkit Jain <radical@corewars.org>
Tue, 25 Jan 2011 23:23:12 +0000 (04:53 +0530)
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConditionAndExpression.cs
mcs/class/Microsoft.Build.Engine/Test/various/Conditions.cs

index 326e055bb43cc0bf5cdfaa0d27343ab90e70e944..55c40d80e924af385c2344e9e2c61bfa8c787de7 100644 (file)
@@ -72,7 +72,9 @@ namespace Microsoft.Build.BuildEngine {
                
                public override bool CanEvaluateToBool (Project context)
                {
-                       return left.CanEvaluateToBool (context) && right.CanEvaluateToBool (context);
+                       // Short-circuiting, check only left expr, right
+                       // would be required only if left == true
+                       return left.CanEvaluateToBool (context);
                }
                
                public override bool CanEvaluateToNumber (Project context)
index 47ef21d41581aa44b195c732111da8aee4d726f6..05ba3b67abc6ad3979d988b3c47a95e869bea0f3 100644 (file)
@@ -336,6 +336,27 @@ namespace MonoTests.Microsoft.Build.BuildEngine.Various {
                        Assert.AreEqual ("fr_c.txt", bgp [2].FinalItemSpec, "A4");
                }
 
+               // Test shortcircuiting
+               [Test]
+               public void TestCondition12 ()
+               {
+                       Engine engine = new Engine (Consts.BinPath);
+                       Project proj = engine.CreateNewProject ();
+
+                       string documentString = @"
+                               <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+                                       <PropertyGroup>
+                                               <A Condition=""'$(NonExistant)' != '' and $(NonExistant)""></A>
+                                       </PropertyGroup>
+                               </Project>
+                       ";
+
+                       proj.LoadXml (documentString);
+
+                       Assert.IsNull (proj.EvaluatedProperties ["A"], "A1");
+               }
+
+
                [Test]
                public void TestHasTrailingSlash1 ()
                {