Skip methods in test-merging if they use the named argument 'Skip' for the Fact attri...
authorWill Smith <lol.tihan@gmail.com>
Fri, 28 Apr 2023 19:22:08 +0000 (12:22 -0700)
committerGitHub <noreply@github.com>
Fri, 28 Apr 2023 19:22:08 +0000 (12:22 -0700)
* Skip methods in test-merging if they use the named argument 'Skip'

* Use ActiveIssueAttribute instead of FactAttribute with Skip. Add documentation about FactAttribute and Skip.

docs/workflow/testing/libraries/filtering-tests.md
src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs
src/tests/JIT/Regression/JitBlue/Runtime_84693/Runtime_84693.cs

index 28ba3e1..35bf2cb 100644 (file)
@@ -337,3 +337,15 @@ A common usage in the libraries tests is the following:
 ```
 
 This is put on test classes to indicate that none of the tests in that class (which as usual run serially with respect to each other) may run concurrently with tests in another class. This is used for tests that use a lot of disk space or memory, or dominate all the cores, such that they are likely to disrupt any tests that run concurrently.
+
+## FactAttribute and `Skip`
+
+Another way to disable the test entirely is to use the `Skip` named argument that is used on the `FactAttribute`.
+
+Example:
+```cs
+[Fact(Skip = "<reason for skipping>")]
+```
+
+If the reason for skipping is a link to an issue, it is recommended to use the `ActiveIssueAttribute` instead.
+Otherwise, `Skip` allows for a more descriptive reason.
index 48182c7..143c3db 100644 (file)
@@ -464,21 +464,35 @@ public sealed class XUnitWrapperGenerator : IIncrementalGenerator
         List<AttributeData> filterAttributes = new();
         foreach (var attr in method.GetAttributesOnSelfAndContainingSymbols())
         {
+            var hasSkip = attr.NamedArguments.Any(x => x.Key == "Skip");
+
             switch (attr.AttributeClass?.ToDisplayString())
             {
                 case "Xunit.ConditionalFactAttribute":
-                    filterAttributes.Add(attr);
-                    factAttribute = true;
+                    if (!hasSkip)
+                    {
+                        filterAttributes.Add(attr);
+                        factAttribute = true;
+                    }
                     break;
                 case "Xunit.FactAttribute":
-                    factAttribute = true;
+                    if (!hasSkip)
+                    {
+                        factAttribute = true;
+                    }
                     break;
                 case "Xunit.ConditionalTheoryAttribute":
-                    filterAttributes.Add(attr);
-                    theoryAttribute = true;
+                    if (!hasSkip)
+                    {
+                        filterAttributes.Add(attr);
+                        theoryAttribute = true;
+                    }
                     break;
                 case "Xunit.TheoryAttribute":
-                    theoryAttribute = true;
+                    if (!hasSkip)
+                    {
+                        theoryAttribute = true;
+                    }
                     break;
                 case "Xunit.ConditionalClassAttribute":
                 case "Xunit.SkipOnPlatformAttribute":
index c7f1a7c..19e39ef 100644 (file)
@@ -28,7 +28,7 @@ public class Test
                }
        }
 
-       [Fact(Skip = "https://github.com/dotnet/runtime/issues/85081")]
+       [ActiveIssue("https://github.com/dotnet/runtime/issues/85081")]
        public static int TestEntryPoint() {
                var result = Test.Program.M8(1);
                if (result != 255)