-
-
Notifications
You must be signed in to change notification settings - Fork 230
Add a message when MSBuild task or target skip due to condition evalu… #769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KirillOsenkov
merged 3 commits into
KirillOsenkov:main
from
yuehuang010:dev/yuehuang/condition_compare
Apr 8, 2024
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using StructuredLogViewer; | ||
| using Xunit; | ||
|
|
||
| namespace StructuredLogger.Tests | ||
| { | ||
| public class ConditionParserTests | ||
| { | ||
| [Fact] | ||
| public void Empty_Test() | ||
| { | ||
| ParseAndAssert(@"", 1, evaluate: false); | ||
| ParseAndAssert(@"( )", 2, evaluate: false); | ||
| ParseAndAssert(@"(() )", 3, evaluate: false); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void EvaluatedNotEqual() | ||
| { | ||
| ParseAndAssert(@"'statement2' != 'statement2'", 2, expectedResult: false); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void EvaluatedEqual() | ||
| { | ||
| ParseAndAssert(@"'statement2' == 'statement2'", 2, expectedResult: true); | ||
| ParseAndAssert(@"'statement2' == ''", 2, expectedResult: false); | ||
| ParseAndAssert(@"'' == 'statement2'", 2, expectedResult: false); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void EvaluatedAnd() | ||
| { | ||
| ParseAndAssert(@"( 'statement1' != '' And 'statement2' != 'statement2' )", 4, expectedResult: false); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void EvaluatedOr() | ||
| { | ||
| ParseAndAssert(@"( 'statement1' != '' Or 'statement2' != 'statement2' )", 4, expectedResult: true); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void EvaluatedNestedStatements() | ||
| { | ||
| string evaluated = @"('statement1' != '' And ('statement2' != 'statement2' or 'statement3' != 'statement3') And 'statement4' != '')"; | ||
|
|
||
| var node = ConditionNode.Parse(evaluated, true); | ||
| Assert.Equal(7, node.Count()); | ||
| Assert.False(node.Result); | ||
| Assert.Equal(2, node.Max(p => p.Level)); | ||
|
|
||
| string evaluatedTrue = @"('statement1' != '' And ('statement2' == 'statement2' or 'statement3' != 'statement3') And 'statement4' != '')"; | ||
|
|
||
| var node2 = ConditionNode.Parse(evaluatedTrue, true); | ||
| Assert.Equal(7, node2.Count()); | ||
| Assert.True(node2.Result); | ||
| Assert.Equal(2, node2.Max(p => p.Level)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Properties() | ||
| { | ||
| string unevaluated = @"('$(Property1)' != '' And '$(Property3)' != '$(Property3)' )"; | ||
| string evaluated = @"( 'statement1' != '' And 'statement2' != 'statement2' )"; | ||
|
|
||
| var node = ConditionNode.ParseAndProcess(unevaluated, evaluated); | ||
| Assert.Equal(4, node.Count()); | ||
| Assert.False(node.Result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Items() | ||
| { | ||
| string unevaluated = @"('@(Item1)' != '' And '@(Item2)' != '@(Item2)' )"; | ||
| string evaluated = @"( 'statement1' != '' And 'statement2' != 'statement2' )"; | ||
|
|
||
| var node = ConditionNode.ParseAndProcess(unevaluated, evaluated); | ||
| Assert.Equal(4, node.Count()); | ||
| Assert.False(node.Result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ItemMetadata() | ||
| { | ||
| string unevaluated = @"('%(Item.Data1)' != '' And '%(Item.Data2)' != '%(Item.Data2)' )"; | ||
| string evaluated = @"( 'statement1' != '' And 'statement2' != 'statement2' )"; | ||
|
|
||
| var node = ConditionNode.ParseAndProcess(unevaluated, evaluated); | ||
| Assert.Equal(4, node.Count()); | ||
| Assert.False(node.Result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ItemTransformation() | ||
| { | ||
| string unevaluated = @"'%(Filename)%(Extension)' != '@(Items->'%(Filename)%(Extension)')'"; | ||
| string evaluated = @"'file.cs' != 'file.cs'"; | ||
|
|
||
| var node = ConditionNode.ParseAndProcess(unevaluated, evaluated); | ||
| Assert.Equal(2, node.Count()); | ||
| Assert.False(node.Result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ConjunctionAnds() | ||
| { | ||
| string unevaluated = @" '$(EnableBaseIntermediateOutputPathMismatchWarning)' == 'true' And '$(_InitialBaseIntermediateOutputPath)' != '$(BaseIntermediateOutputPath)' And '$(BaseIntermediateOutputPath)' != '$(MSBuildProjectExtensionsPath)' "; | ||
| string evaluatedFalse = @"'' == 'true' And '' != 'obj\' And 'obj\' != 'project\obj\'"; | ||
|
|
||
| var node = ConditionNode.ParseAndProcess(unevaluated, evaluatedFalse); | ||
| Assert.Equal(4, node.Count()); | ||
| Assert.False(node.Result); | ||
|
|
||
| string evaluatedTrue = @"'true' == 'true' And '' != 'obj\' And '' != 'project\obj\'"; | ||
|
|
||
| var node2 = ConditionNode.ParseAndProcess(unevaluated, evaluatedTrue); | ||
| Assert.Equal(4, node2.Count()); | ||
| Assert.True(node2.Result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ConjunctionOrs() | ||
| { | ||
| string unevaluated = @" '$(EnableBaseIntermediateOutputPathMismatchWarning)' == 'true' Or '$(_InitialBaseIntermediateOutputPath)' != '$(BaseIntermediateOutputPath)' Or '$(BaseIntermediateOutputPath)' != '$(MSBuildProjectExtensionsPath)' "; | ||
| string evaluatedTrue = @"'' == 'true' Or 'obj\' != 'obj\' Or 'obj\' != 'project\obj\'"; | ||
|
|
||
| var node = ConditionNode.ParseAndProcess(unevaluated, evaluatedTrue); | ||
| Assert.Equal(4, node.Count()); | ||
| Assert.True(node.Result); | ||
|
|
||
| string evaluatedFalse = @"'' == 'true' Or 'obj\' != 'obj\' Or 'project\obj\' != 'project\obj\'"; | ||
|
|
||
| var node2 = ConditionNode.ParseAndProcess(unevaluated, evaluatedFalse); | ||
| Assert.Equal(4, node2.Count()); | ||
| Assert.False(node2.Result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ExistsNot() | ||
| { | ||
| var node = ParseAndAssert(@"!Exists($(File))", 2, evaluate: false); | ||
| Assert.Equal("!Exists($(File))", node.Children[0].Text); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Exists() | ||
| { | ||
| var node = ParseAndAssert(@"Exists($(File))", 2, evaluate: false); | ||
| Assert.Equal("Exists($(File))", node.Children[0].Text); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void NoQuotesProperty() | ||
| { | ||
| var node = ParseAndAssert(@"$(file) == ''", 2, evaluate: false); | ||
| Assert.Equal("$(file)==''", node.Children[0].Text); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void NumericCompareDouble() | ||
| { | ||
| ParseAndAssert(@"'123.456' < '567.123'", 2, expectedResult: true); | ||
| ParseAndAssert(@"'123.456' <= '567.123'", 2, expectedResult: true); | ||
| ParseAndAssert(@"'123.456' > '567.123'", 2, expectedResult: false); | ||
| ParseAndAssert(@"'123.456' >= '567.123'", 2, expectedResult: false); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void NumericCompareVersion() | ||
| { | ||
| ParseAndAssert(@"'123.456.789' < '567.123.456'", 2, expectedResult: true); | ||
| ParseAndAssert(@"'123.456.789' <= '567.123.456'", 2, expectedResult: true); | ||
| ParseAndAssert(@"'123.456.789' > '567.123.456'", 2, expectedResult: false); | ||
| ParseAndAssert(@"'123.456.789' >= '567.123.456'", 2, expectedResult: false); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Boolean() | ||
| { | ||
| // test with whitespace | ||
| var node = ParseAndAssert(@" false ", 2, expectedResult: false); | ||
| Assert.Equal("false", node.Children[0].Text); | ||
|
|
||
| var node2 = ParseAndAssert(@"true", 2, expectedResult: true); | ||
| Assert.Equal("true", node2.Children[0].Text); | ||
|
|
||
| var node3 = ParseAndAssert(@"!false", 2, expectedResult: true); | ||
| Assert.Equal("!false", node3.Children[0].Text); | ||
| } | ||
|
|
||
| private static ConditionNode ParseAndAssert(string text, int expectedCount, bool evaluate = true, bool expectedResult = true) | ||
| { | ||
| var node = ConditionNode.Parse(text, evaluate); | ||
|
|
||
| if (expectedCount == 1) | ||
| { | ||
| Assert.Single(node); | ||
| } | ||
| else | ||
| { | ||
| Assert.Equal(expectedCount, node.Count()); | ||
| } | ||
|
|
||
| if (evaluate) | ||
| { | ||
| if (expectedResult) | ||
| { | ||
| Assert.True(node.Result); | ||
| } | ||
| else | ||
| { | ||
| Assert.False(node.Result); | ||
| } | ||
| } | ||
|
|
||
| return node; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this logic perhaps go into BuildControl.xaml.cs -> DisplayText() on line 2371?
Also maybe extract method so that this logic is a separate method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand perhaps keep it here, maybe in the future we can do smart highlighting to highlight substrings using the textEditor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still, I'd extract this logic to a separate method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to a separate function. I wanted to add Outlining to help visualize the position, but it might be too visually busy. Maybe in the future, it could have toggle button.