Skip to content

Commit 3906381

Browse files
committed
FSharp tests: don't use standard output for benchmark failure verification
1 parent 5394383 commit 3906381

File tree

8 files changed

+16
-45
lines changed

8 files changed

+16
-45
lines changed

tests/BenchmarkDotNet.IntegrationTests.FSharp/Program.fs

+2-6
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ type Db() =
2828
type TestEnum = | A = 0 | B = 1 | C = 2
2929

3030
type EnumParamsTest() =
31-
let mutable collectedParams = HashSet<TestEnum>()
32-
33-
[<Params(TestEnum.A, TestEnum.B)>]
31+
[<Params(TestEnum.B)>]
3432
member val EnumParamValue = TestEnum.A with get, set
3533

3634
[<Benchmark>]
3735
member this.Benchmark() =
38-
if not <| collectedParams.Contains(this.EnumParamValue) then
39-
printfn "// ### New Parameter %A ###" this.EnumParamValue
40-
collectedParams.Add(this.EnumParamValue) |> ignore
36+
if not (this.EnumParamValue = TestEnum.B) then failwith "Invalid Params value assigned"

tests/BenchmarkDotNet.IntegrationTests/AllSetupAndCleanupTest.cs

+6-12
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ private static string[] GetActualLogLines(Summary summary)
5252
[Fact]
5353
public void AllSetupAndCleanupMethodRunsTest()
5454
{
55-
var logger = new OutputLogger(Output);
5655
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");
57-
var config = CreateSimpleConfig(logger, miniJob);
56+
var config = CreateSimpleConfig(job: miniJob);
5857

5958
var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarks>(config);
6059

@@ -88,9 +87,8 @@ public class AllSetupAndCleanupAttributeBenchmarks
8887
[Fact]
8988
public void AllSetupAndCleanupMethodRunsAsyncTest()
9089
{
91-
var logger = new OutputLogger(Output);
9290
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");
93-
var config = CreateSimpleConfig(logger, miniJob);
91+
var config = CreateSimpleConfig(job: miniJob);
9492

9593
var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsync>(config);
9694

@@ -124,9 +122,8 @@ public class AllSetupAndCleanupAttributeBenchmarksAsync
124122
[Fact]
125123
public void AllSetupAndCleanupMethodRunsAsyncTaskSetupTest()
126124
{
127-
var logger = new OutputLogger(Output);
128125
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");
129-
var config = CreateSimpleConfig(logger, miniJob);
126+
var config = CreateSimpleConfig(job: miniJob);
130127

131128
var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsyncTaskSetup>(config);
132129

@@ -160,9 +157,8 @@ public class AllSetupAndCleanupAttributeBenchmarksAsyncTaskSetup
160157
[Fact]
161158
public void AllSetupAndCleanupMethodRunsAsyncGenericTaskSetupTest()
162159
{
163-
var logger = new OutputLogger(Output);
164160
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");
165-
var config = CreateSimpleConfig(logger, miniJob);
161+
var config = CreateSimpleConfig(job: miniJob);
166162

167163
var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsyncGenericTaskSetup>(config);
168164

@@ -206,9 +202,8 @@ public async Task<int> GlobalCleanup()
206202
[Fact]
207203
public void AllSetupAndCleanupMethodRunsAsyncValueTaskSetupTest()
208204
{
209-
var logger = new OutputLogger(Output);
210205
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");
211-
var config = CreateSimpleConfig(logger, miniJob);
206+
var config = CreateSimpleConfig(job: miniJob);
212207

213208
var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsyncValueTaskSetup>(config);
214209

@@ -242,9 +237,8 @@ public class AllSetupAndCleanupAttributeBenchmarksAsyncValueTaskSetup
242237
[FactNotGitHubActionsWindows]
243238
public void AllSetupAndCleanupMethodRunsAsyncGenericValueTaskSetupTest()
244239
{
245-
var logger = new OutputLogger(Output);
246240
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");
247-
var config = CreateSimpleConfig(logger, miniJob);
241+
var config = CreateSimpleConfig(job: miniJob);
248242

249243
var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsyncGenericValueTaskSetup>(config);
250244

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
2-
using Xunit;
1+
using Xunit;
32
using Xunit.Abstractions;
4-
5-
using BenchmarkDotNet.Tests.Loggers;
63
using static FSharpBenchmarks;
74

85
namespace BenchmarkDotNet.IntegrationTests
@@ -12,15 +9,6 @@ public class FSharpTests : BenchmarkTestExecutor
129
public FSharpTests(ITestOutputHelper output) : base(output) { }
1310

1411
[Fact]
15-
public void ParamsSupportFSharpEnums()
16-
{
17-
var logger = new OutputLogger(Output);
18-
var config = CreateSimpleConfig(logger);
19-
20-
CanExecute<EnumParamsTest>(config);
21-
foreach (var param in new[] { TestEnum.A, TestEnum.B })
22-
Assert.Contains($"// ### New Parameter {param} ###" + Environment.NewLine, logger.GetLog());
23-
Assert.DoesNotContain($"// ### New Parameter {TestEnum.C} ###" + Environment.NewLine, logger.GetLog());
24-
}
12+
public void ParamsSupportFSharpEnums() => CanExecute<EnumParamsTest>();
2513
}
2614
}

tests/BenchmarkDotNet.IntegrationTests/PowerManagementApplierTests.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public PowerManagementApplierTests(ITestOutputHelper output) : base(output) { }
1818
public void TestSettingAndRevertingBackGuid()
1919
{
2020
var userPlan = PowerManagementHelper.CurrentPlan;
21-
var logger = new OutputLogger(Output);
22-
var powerManagementApplier = new PowerManagementApplier(logger);
21+
var powerManagementApplier = new PowerManagementApplier(new OutputLogger(Output));
2322

2423
powerManagementApplier.ApplyPerformancePlan(PowerManagementApplier.Map(PowerPlan.HighPerformance));
2524

@@ -34,8 +33,7 @@ public void TestSettingAndRevertingBackGuid()
3433
public void TestPowerPlanShouldNotChange()
3534
{
3635
var userPlan = PowerManagementHelper.CurrentPlan;
37-
var logger = new OutputLogger(Output);
38-
var powerManagementApplier = new PowerManagementApplier(logger);
36+
var powerManagementApplier = new PowerManagementApplier(new OutputLogger(Output));
3937

4038
powerManagementApplier.ApplyPerformancePlan(PowerManagementApplier.Map(PowerPlan.UserPowerPlan));
4139

tests/BenchmarkDotNet.IntegrationTests/PriorityTests.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public PriorityTests(ITestOutputHelper output) : base(output) { }
1414
[Fact]
1515
public void ParamsSupportPropertyWithPublicSetter()
1616
{
17-
var logger = new OutputLogger(Output);
18-
var config = CreateSimpleConfig(logger);
17+
var config = CreateSimpleConfig();
1918

2019
var summary = CanExecute<PriorityBenchmark>(config);
2120
var columns = summary.Table.Columns;

tests/BenchmarkDotNet.IntegrationTests/ProcessorArchitectureTest.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ public void SpecifiedProcessorArchitectureMustBeRespected()
2727

2828
private void Verify(Platform platform, Type benchmark)
2929
{
30-
var logger = new OutputLogger(Output);
31-
3230
var config = ManualConfig.CreateEmpty()
3331
.AddJob(Job.Dry.WithPlatform(platform))
34-
.AddLogger(logger); // make sure we get an output in the TestRunner log
32+
.AddLogger(new OutputLogger(Output)); // make sure we get an output in the TestRunner log
3533

3634
// CanExecute ensures that at least one benchmark has executed successfully
3735
CanExecute(benchmark, config, fullValidation: true);

tests/BenchmarkDotNet.IntegrationTests/RoslynToolchainTest.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ public void CanExecuteWithNonDefaultUiCulture(string culture)
3131
CultureInfo.CurrentCulture = overrideCulture;
3232
CultureInfo.CurrentUICulture = overrideCulture;
3333

34-
var logger = new OutputLogger(Output);
3534
var miniJob = Job.Dry.WithToolchain(RoslynToolchain.Instance);
36-
var config = CreateSimpleConfig(logger, miniJob);
35+
var config = CreateSimpleConfig(job: miniJob);
3736

3837
CanExecute<SimpleBenchmarks>(config);
3938
}

tests/BenchmarkDotNet.IntegrationTests/SetupAndCleanupTests.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ public SetupAndCleanupTests(ITestOutputHelper output) : base(output) { }
7878
[Fact]
7979
public void AllSetupAndCleanupMethodRunsForSpecificBenchmark()
8080
{
81-
var logger = new OutputLogger(Output);
8281
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");
83-
var config = CreateSimpleConfig(logger, miniJob);
82+
var config = CreateSimpleConfig(job: miniJob);
8483

8584
var summary = CanExecute<Benchmarks>(config);
8685
var standardOutput = GetCombinedStandardOutput(summary);

0 commit comments

Comments
 (0)