Skip to content

Commit 28809a1

Browse files
Rework environment-specific custom xUnit attributes
1 parent ab17946 commit 28809a1

39 files changed

+143
-200
lines changed

tests/BenchmarkDotNet.IntegrationTests/AllSetupAndCleanupTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public class AllSetupAndCleanupAttributeBenchmarksAsyncValueTaskSetup
234234
public void Benchmark() => Console.WriteLine(BenchmarkCalled);
235235
}
236236

237-
[FactNotGitHubActionsWindows]
237+
[FactEnvSpecific(EnvRequirement.NonWindows)]
238238
public void AllSetupAndCleanupMethodRunsAsyncGenericValueTaskSetupTest()
239239
{
240240
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");

tests/BenchmarkDotNet.IntegrationTests/ArgumentsTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,9 @@ public void AcceptsSpan(Span<int> span)
318318
}
319319
}
320320

321-
[TheoryNetCoreOnly("the implicit cast operator is available only in .NET Core 2.1+ (See https://github.com/dotnet/corefx/issues/30121 for more)"),
322-
MemberData(nameof(GetToolchains))]
321+
[TheoryEnvSpecific("The implicit cast operator is available only in .NET Core 2.1+ (See https://github.com/dotnet/corefx/issues/30121 for more)",
322+
EnvRequirement.DotNetCoreOnly)]
323+
[MemberData(nameof(GetToolchains))]
323324
public void StringCanBePassedToBenchmarkAsReadOnlySpan(IToolchain toolchain) => CanExecute<WithStringToReadOnlySpan>(toolchain);
324325

325326
public class WithStringToReadOnlySpan

tests/BenchmarkDotNet.IntegrationTests/BenchmarkSwitcherTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public class BenchmarkSwitcherTest
2525

2626
public BenchmarkSwitcherTest(ITestOutputHelper output) => Output = output;
2727

28-
[FactDotNetCoreOnly("When CommandLineParser wants to display help, it tries to get the Title of the Entry Assembly which is an xunit runner, which has no Title and fails..")]
28+
[FactEnvSpecific(
29+
"When CommandLineParser wants to display help, it tries to get the Title of the Entry Assembly which is an xunit runner, which has no Title and fails..",
30+
EnvRequirement.DotNetCoreOnly)]
2931
public void WhenInvalidCommandLineArgumentIsPassedAnErrorMessageIsDisplayedAndNoBenchmarksAreExecuted()
3032
{
3133
var logger = new OutputLogger(Output);
@@ -332,7 +334,7 @@ public void WhenUserCreatesStaticBenchmarkMethodWeDisplayAnError_FromAssembly()
332334
Assert.Contains("static", logger.GetLog());
333335
}
334336

335-
[FactDotNetCoreOnly("For some reason this test is flaky on Full Framework")]
337+
[FactEnvSpecific("For some reason this test is flaky on Full Framework", EnvRequirement.DotNetCoreOnly)]
336338
public void WhenUserAddTheResumeAttributeAndRunTheBenchmarks()
337339
{
338340
var logger = new OutputLogger(Output);

tests/BenchmarkDotNet.IntegrationTests/ExporterIOTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void ExporterWritesToFile()
4242
}
4343
}
4444

45-
[FactWindowsOnly("On Unix, it's possible to write to an opened file")]
45+
[FactEnvSpecific("On Unix, it's possible to write to an opened file", EnvRequirement.WindowsOnly)]
4646
public void ExporterWorksWhenFileIsLocked()
4747
{
4848
string resultsDirectoryPath = Path.GetTempPath();

tests/BenchmarkDotNet.IntegrationTests/ExtraAttributesForEntryMethodTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public ExtraAttributesForEntryMethodTests(ITestOutputHelper output) : base(outpu
1111
{
1212
}
1313

14-
[FactClassicDotNetOnly("STAThread attribute is not respected in netcoreapp https://github.com/dotnet/coreclr/issues/13688")]
14+
[FactEnvSpecific("STAThread attribute is not respected in netcoreapp https://github.com/dotnet/coreclr/issues/13688", EnvRequirement.FullFrameworkOnly)]
1515
public void UserCanMarkBenchmarkAsRequiringSTA() => CanExecute<RequiresSTA>();
1616

1717
public class RequiresSTA

tests/BenchmarkDotNet.IntegrationTests/InProcessEmitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void InProcessBenchmarkSimpleCasesReflectionEmitSupported()
104104
}
105105
}
106106

107-
[TheoryFullFrameworkOnly("We can't use Roslyn toolchain for .NET Core because we don't know which assemblies to reference and .NET Core does not support dynamic assembly saving")]
107+
[TheoryEnvSpecific("We can't use Roslyn toolchain for .NET Core because we don't know which assemblies to reference and .NET Core does not support dynamic assembly saving", EnvRequirement.FullFrameworkOnly)]
108108
[InlineData(typeof(SampleBenchmark))]
109109
[InlineData(typeof(RunnableVoidCaseBenchmark))]
110110
[InlineData(typeof(RunnableRefStructCaseBenchmark))]

tests/BenchmarkDotNet.IntegrationTests/JitRuntimeValidationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public JitRuntimeValidationTest(ITestOutputHelper output) : base(output) { }
2020
private const string RyuJitNotAvailable = "// ERROR: RyuJIT is requested but it is not available in current environment";
2121
private const string ToolchainSupportsOnlyRyuJit = "Currently dotnet cli toolchain supports only RyuJit";
2222

23-
[TheoryWindowsOnly("CLR is a valid job only on Windows")]
23+
[TheoryEnvSpecific("CLR is a valid job only on Windows", EnvRequirement.WindowsOnly)]
2424
[InlineData(Jit.LegacyJit, Platform.X86, null)]
2525
[InlineData(Jit.LegacyJit, Platform.X64, null)]
2626
[InlineData(Jit.RyuJit, Platform.X86, RyuJitNotAvailable)]

tests/BenchmarkDotNet.IntegrationTests/LargeAddressAwareTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class LargeAddressAwareTest
1919

2020
public LargeAddressAwareTest(ITestOutputHelper outputHelper) => output = outputHelper;
2121

22-
[FactWindowsOnly("CLR is a valid job only on Windows")]
22+
[FactEnvSpecific("CLR is a valid job only on Windows", EnvRequirement.WindowsOnly)]
2323
public void BenchmarkCanAllocateMoreThan2Gb()
2424
{
2525
var summary = BenchmarkRunner

tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void MemoryDiagnoserIsAccurate(IToolchain toolchain)
7070
});
7171
}
7272

73-
[FactDotNetCoreOnly("We don't want to test NativeAOT twice (for .NET Framework 4.6.2 and .NET 7.0)")]
73+
[FactEnvSpecific("We don't want to test NativeAOT twice (for .NET Framework 4.6.2 and .NET 7.0)", EnvRequirement.DotNetCoreOnly)]
7474
public void MemoryDiagnoserSupportsNativeAOT()
7575
{
7676
if (RuntimeInformation.IsMacOS())
@@ -82,7 +82,7 @@ public void MemoryDiagnoserSupportsNativeAOT()
8282
.ToToolchain());
8383
}
8484

85-
[FactDotNetCoreOnly("We don't want to test MonoVM twice (for .NET Framework 4.6.2 and .NET 7.0)")]
85+
[FactEnvSpecific("We don't want to test MonoVM twice (for .NET Framework 4.6.2 and .NET 7.0)", EnvRequirement.DotNetCoreOnly)]
8686
public void MemoryDiagnoserSupportsModernMono()
8787
{
8888
MemoryDiagnoserIsAccurate(MonoToolchain.Mono70);
@@ -263,7 +263,9 @@ public void Allocate()
263263
}
264264
}
265265

266-
[TheoryNetCore30(".NET Core 3.0 preview6+ exposes a GC.GetTotalAllocatedBytes method which makes it possible to work"), MemberData(nameof(GetToolchains))]
266+
[TheoryEnvSpecific(".NET Core 3.0 preview6+ exposes a GC.GetTotalAllocatedBytes method which makes it possible to work",
267+
EnvRequirement.DotNetCore30Only)]
268+
[MemberData(nameof(GetToolchains))]
267269
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
268270
public void MemoryDiagnoserIsAccurateForMultiThreadedBenchmarks(IToolchain toolchain)
269271
{

tests/BenchmarkDotNet.IntegrationTests/MonoTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace BenchmarkDotNet.IntegrationTests
1010
{
1111
public class MonoTests : BenchmarkTestExecutor
1212
{
13-
[FactDotNetCoreOnly("UseMonoRuntime option is available in .NET Core only starting from .NET 6")]
13+
[FactEnvSpecific("UseMonoRuntime option is available in .NET Core only starting from .NET 6", EnvRequirement.DotNetCoreOnly)]
1414
public void Mono70IsSupported()
1515
{
1616
var config = ManualConfig.CreateEmpty().AddJob(Job.Dry.WithRuntime(MonoRuntime.Mono70));

0 commit comments

Comments
 (0)