diff --git a/Directory.Build.props b/Directory.Build.props
index 87fa852..bb79b93 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -29,6 +29,7 @@
+
diff --git a/src/Xunit.SkippableFact/Skip.cs b/src/Xunit.SkippableFact/Skip.cs
index 345e5e4..8c5ec7a 100644
--- a/src/Xunit.SkippableFact/Skip.cs
+++ b/src/Xunit.SkippableFact/Skip.cs
@@ -3,6 +3,8 @@
namespace Xunit
{
+ using System.Diagnostics.CodeAnalysis;
+
///
/// Static methods for dynamically skipping tests identified with
/// the .
@@ -14,7 +16,9 @@ public static class Skip
///
/// The condition that must evaluate to true for the test to be skipped.
/// The explanation for why the test is skipped.
- public static void If(bool condition, string? reason = null)
+ public static void If(
+ [DoesNotReturnIf(true)] bool condition,
+ string? reason = null)
{
if (condition)
{
@@ -27,7 +31,9 @@ public static void If(bool condition, string? reason = null)
///
/// The condition that must evaluate to false for the test to be skipped.
/// The explanation for why the test is skipped.
- public static void IfNot(bool condition, string? reason = null)
+ public static void IfNot(
+ [DoesNotReturnIf(false)] bool condition,
+ string? reason = null)
{
Skip.If(!condition, reason);
}
diff --git a/src/Xunit.SkippableFact/Xunit.SkippableFact.csproj b/src/Xunit.SkippableFact/Xunit.SkippableFact.csproj
index 0c0e4bb..b16fd6b 100644
--- a/src/Xunit.SkippableFact/Xunit.SkippableFact.csproj
+++ b/src/Xunit.SkippableFact/Xunit.SkippableFact.csproj
@@ -11,7 +11,7 @@
PreserveNewest
-
+
diff --git a/test/Xunit.SkippableFact.Tests/SkipTests.cs b/test/Xunit.SkippableFact.Tests/SkipTests.cs
index 7378263..0ea1ef6 100644
--- a/test/Xunit.SkippableFact.Tests/SkipTests.cs
+++ b/test/Xunit.SkippableFact.Tests/SkipTests.cs
@@ -48,5 +48,37 @@ public void IfNot_WithReason()
Assert.Equal(reason, ex.Message);
}
}
+
+ [Fact]
+ public void If_SupportsNullableReferenceTypesPostCondition()
+ {
+ // Provoke a possibly null value that is not detectable through
+ // static analysis
+ string? value =
+ int.Parse("42", System.Globalization.CultureInfo.InvariantCulture) == 42
+ ? "Not null"
+ : null;
+
+ Skip.If(value is null);
+
+ // Does not trigger a nullable reference type warning
+ _ = value.Substring(0);
+ }
+
+ [Fact]
+ public void IfNot_SupportsNullableReferenceTypesPostCondition()
+ {
+ // Provoke a possibly null value that is not detectable through
+ // static analysis
+ string? value =
+ int.Parse("42", System.Globalization.CultureInfo.InvariantCulture) == 42
+ ? "Not null"
+ : null;
+
+ Skip.IfNot(value is object);
+
+ // Does not trigger a nullable reference type warning
+ _ = value.Substring(0);
+ }
}
}