From 095d0641e6bc9e0d4b25f609b7fbd26c6c7b0726 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Fri, 24 Apr 2020 11:26:06 -0600 Subject: [PATCH] Respect `methodDisplayOptions` Fixes #14 --- .../Sdk/SkippableFactDiscoverer.cs | 4 ++++ .../Sdk/SkippableFactTestCase.cs | 18 ++++++++++++++++++ .../Sdk/SkippableTheoryDiscoverer.cs | 8 ++++++++ .../Sdk/SkippableTheoryTestCase.cs | 17 +++++++++++++++++ .../Xunit.SkippableFact.csproj | 5 +++++ src/Xunit.SkippableFact/xunit.runner.json | 5 +++++ 6 files changed, 57 insertions(+) create mode 100644 src/Xunit.SkippableFact/xunit.runner.json diff --git a/src/Xunit.SkippableFact/Sdk/SkippableFactDiscoverer.cs b/src/Xunit.SkippableFact/Sdk/SkippableFactDiscoverer.cs index f585193..1a815c6 100644 --- a/src/Xunit.SkippableFact/Sdk/SkippableFactDiscoverer.cs +++ b/src/Xunit.SkippableFact/Sdk/SkippableFactDiscoverer.cs @@ -50,7 +50,11 @@ public virtual IEnumerable Discover(ITestFrameworkDiscoveryOptio { Requires.NotNull(factAttribute, nameof(factAttribute)); string[] skippingExceptionNames = GetSkippableExceptionNames(factAttribute); +#if NET45 yield return new SkippableFactTestCase(skippingExceptionNames, this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod); +#else + yield return new SkippableFactTestCase(skippingExceptionNames, this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod); +#endif } } } diff --git a/src/Xunit.SkippableFact/Sdk/SkippableFactTestCase.cs b/src/Xunit.SkippableFact/Sdk/SkippableFactTestCase.cs index e4e4cbe..5154e84 100644 --- a/src/Xunit.SkippableFact/Sdk/SkippableFactTestCase.cs +++ b/src/Xunit.SkippableFact/Sdk/SkippableFactTestCase.cs @@ -46,6 +46,24 @@ public SkippableFactTestCase(string[] skippingExceptionNames, IMessageSink diagn this.SkippingExceptionNames = skippingExceptionNames; } +#if !NET45 + /// + /// Initializes a new instance of the class. + /// + /// An array of the full names of the exception types which should be interpreted as a skipped test-. + /// The diagnostic message sink. + /// The preferred test name derivation. + /// Default method display options to use (when not customized). + /// The test method. + /// The test method arguments. + public SkippableFactTestCase(string[] skippingExceptionNames, IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod, object[]? testMethodArguments = null) + : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments) + { + Requires.NotNull(skippingExceptionNames, nameof(skippingExceptionNames)); + this.SkippingExceptionNames = skippingExceptionNames; + } +#endif + /// /// Gets an array of full names to exception types that should be interpreted as a skip result. /// diff --git a/src/Xunit.SkippableFact/Sdk/SkippableTheoryDiscoverer.cs b/src/Xunit.SkippableFact/Sdk/SkippableTheoryDiscoverer.cs index 6e96713..c404e71 100644 --- a/src/Xunit.SkippableFact/Sdk/SkippableTheoryDiscoverer.cs +++ b/src/Xunit.SkippableFact/Sdk/SkippableTheoryDiscoverer.cs @@ -48,11 +48,19 @@ public virtual IEnumerable Discover(ITestFrameworkDiscoveryOptio { if (testCase is XunitTheoryTestCase) { +#if NET45 yield return new SkippableTheoryTestCase(skippingExceptionNames, this.diagnosticMessageSink, defaultMethodDisplay, testCase.TestMethod); +#else + yield return new SkippableTheoryTestCase(skippingExceptionNames, this.diagnosticMessageSink, defaultMethodDisplay, discoveryOptions.MethodDisplayOptionsOrDefault(), testCase.TestMethod); +#endif } else { +#if NET45 yield return new SkippableFactTestCase(skippingExceptionNames, this.diagnosticMessageSink, defaultMethodDisplay, testCase.TestMethod, testCase.TestMethodArguments); +#else + yield return new SkippableFactTestCase(skippingExceptionNames, this.diagnosticMessageSink, defaultMethodDisplay, discoveryOptions.MethodDisplayOptionsOrDefault(), testCase.TestMethod, testCase.TestMethodArguments); +#endif } } } diff --git a/src/Xunit.SkippableFact/Sdk/SkippableTheoryTestCase.cs b/src/Xunit.SkippableFact/Sdk/SkippableTheoryTestCase.cs index 7ca537a..4dd351f 100644 --- a/src/Xunit.SkippableFact/Sdk/SkippableTheoryTestCase.cs +++ b/src/Xunit.SkippableFact/Sdk/SkippableTheoryTestCase.cs @@ -45,6 +45,23 @@ public SkippableTheoryTestCase(string[] skippingExceptionNames, IMessageSink dia this.SkippingExceptionNames = skippingExceptionNames; } +#if !NET45 + /// + /// Initializes a new instance of the class. + /// + /// An array of the full names of the exception types which should be interpreted as a skipped test-. + /// The diagnostic message sink. + /// The preferred test name derivation. + /// Default method display options to use (when not customized). + /// The test method. + public SkippableTheoryTestCase(string[] skippingExceptionNames, IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod) + : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod) + { + Requires.NotNull(skippingExceptionNames, nameof(skippingExceptionNames)); + this.SkippingExceptionNames = skippingExceptionNames; + } +#endif + /// /// Gets an array of the full names of the exception types which should be interpreted as a skipped test. /// diff --git a/src/Xunit.SkippableFact/Xunit.SkippableFact.csproj b/src/Xunit.SkippableFact/Xunit.SkippableFact.csproj index 3a1d2ec..0c0e4bb 100644 --- a/src/Xunit.SkippableFact/Xunit.SkippableFact.csproj +++ b/src/Xunit.SkippableFact/Xunit.SkippableFact.csproj @@ -7,6 +7,11 @@ Make your Xunit test methods self-determine to report a "skipped" result. Useful for such cases as "not supported on this platform" results or other environmental inputs. xunit testing skipping + + + PreserveNewest + + diff --git a/src/Xunit.SkippableFact/xunit.runner.json b/src/Xunit.SkippableFact/xunit.runner.json new file mode 100644 index 0000000..5b7dfed --- /dev/null +++ b/src/Xunit.SkippableFact/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "methodDisplayOptions": "all", + "methodDisplay": "method" +}