File tree Expand file tree Collapse file tree 2 files changed +47
-2
lines changed
xunit.analyzers.tests/Analyzers/X1000 Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 11using System . Threading . Tasks ;
2+ using Microsoft . CodeAnalysis . CSharp ;
23using Xunit ;
34using Verify = CSharpVerifier < Xunit . Analyzers . TestMethodShouldNotBeSkipped > ;
45
@@ -33,4 +34,36 @@ public void TestMethod() {{ }}
3334
3435 await Verify . VerifyAnalyzer ( source ) ;
3536 }
37+
38+ [ Theory ]
39+ [ InlineData ( "Fact" ) ]
40+ [ InlineData ( "Theory" ) ]
41+ public async Task SkippedTestWhenConditionIsTrue_V3_DoesNotTrigger ( string attribute )
42+ {
43+ var source = string . Format ( /* lang=c#-test */ """
44+ public class TestClass {{
45+ public static bool Condition {{ get; set; }}
46+ [Xunit.{0}(Skip="Lazy", SkipWhen=nameof(Condition))]
47+ public void TestMethod() {{ }}
48+ }}
49+ """ , attribute ) ;
50+
51+ await Verify . VerifyAnalyzerV3 ( LanguageVersion . CSharp7 , source ) ;
52+ }
53+
54+ [ Theory ]
55+ [ InlineData ( "Fact" ) ]
56+ [ InlineData ( "Theory" ) ]
57+ public async Task SkippedTestUnlessConditionIsTrue_V3_DoesNotTrigger ( string attribute )
58+ {
59+ var source = string . Format ( /* lang=c#-test */ """
60+ public class TestClass {{
61+ public static bool Condition {{ get; set; }}
62+ [Xunit.{0}(Skip="Lazy", SkipUnless=nameof(Condition))]
63+ public void TestMethod() {{ }}
64+ }}
65+ """ , attribute ) ;
66+
67+ await Verify . VerifyAnalyzerV3 ( LanguageVersion . CSharp7 , source ) ;
68+ }
3669}
Original file line number Diff line number Diff line change 1- using System . Linq ;
21using Microsoft . CodeAnalysis ;
32using Microsoft . CodeAnalysis . CSharp ;
43using Microsoft . CodeAnalysis . CSharp . Syntax ;
@@ -26,8 +25,21 @@ public override void AnalyzeCompilation(
2625 return ;
2726 if ( context . Node is not AttributeSyntax attribute )
2827 return ;
28+ if ( attribute . ArgumentList is null )
29+ return ;
30+
31+ var skipArgument = default ( AttributeArgumentSyntax ) ;
32+ foreach ( var argument in attribute . ArgumentList . Arguments )
33+ {
34+ var valueText = argument . NameEquals ? . Name ? . Identifier . ValueText ;
35+
36+ if ( valueText == "SkipWhen" || valueText == "SkipUnless" )
37+ return ;
38+
39+ if ( valueText == "Skip" )
40+ skipArgument = argument ;
41+ }
2942
30- var skipArgument = attribute . ArgumentList ? . Arguments . FirstOrDefault ( arg => arg . NameEquals ? . Name ? . Identifier . ValueText == "Skip" ) ;
3143 if ( skipArgument is null )
3244 return ;
3345
You can’t perform that action at this time.
0 commit comments