Skip to content

Commit

Permalink
FSharp tests: don't use standard output for benchmark failure verific…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
adamsitnik committed Sep 14, 2022
1 parent 5394383 commit 3906381
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 45 deletions.
8 changes: 2 additions & 6 deletions tests/BenchmarkDotNet.IntegrationTests.FSharp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ type Db() =
type TestEnum = | A = 0 | B = 1 | C = 2

type EnumParamsTest() =
let mutable collectedParams = HashSet<TestEnum>()

[<Params(TestEnum.A, TestEnum.B)>]
[<Params(TestEnum.B)>]
member val EnumParamValue = TestEnum.A with get, set

[<Benchmark>]
member this.Benchmark() =
if not <| collectedParams.Contains(this.EnumParamValue) then
printfn "// ### New Parameter %A ###" this.EnumParamValue
collectedParams.Add(this.EnumParamValue) |> ignore
if not (this.EnumParamValue = TestEnum.B) then failwith "Invalid Params value assigned"
18 changes: 6 additions & 12 deletions tests/BenchmarkDotNet.IntegrationTests/AllSetupAndCleanupTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ private static string[] GetActualLogLines(Summary summary)
[Fact]
public void AllSetupAndCleanupMethodRunsTest()
{
var logger = new OutputLogger(Output);
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");
var config = CreateSimpleConfig(logger, miniJob);
var config = CreateSimpleConfig(job: miniJob);

var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarks>(config);

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

var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsync>(config);

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

var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsyncTaskSetup>(config);

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

var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsyncGenericTaskSetup>(config);

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

var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsyncValueTaskSetup>(config);

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

var summary = CanExecute<AllSetupAndCleanupAttributeBenchmarksAsyncGenericValueTaskSetup>(config);

Expand Down
16 changes: 2 additions & 14 deletions tests/BenchmarkDotNet.IntegrationTests/FSharpTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using Xunit;
using Xunit;
using Xunit.Abstractions;

using BenchmarkDotNet.Tests.Loggers;
using static FSharpBenchmarks;

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

[Fact]
public void ParamsSupportFSharpEnums()
{
var logger = new OutputLogger(Output);
var config = CreateSimpleConfig(logger);

CanExecute<EnumParamsTest>(config);
foreach (var param in new[] { TestEnum.A, TestEnum.B })
Assert.Contains($"// ### New Parameter {param} ###" + Environment.NewLine, logger.GetLog());
Assert.DoesNotContain($"// ### New Parameter {TestEnum.C} ###" + Environment.NewLine, logger.GetLog());
}
public void ParamsSupportFSharpEnums() => CanExecute<EnumParamsTest>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public PowerManagementApplierTests(ITestOutputHelper output) : base(output) { }
public void TestSettingAndRevertingBackGuid()
{
var userPlan = PowerManagementHelper.CurrentPlan;
var logger = new OutputLogger(Output);
var powerManagementApplier = new PowerManagementApplier(logger);
var powerManagementApplier = new PowerManagementApplier(new OutputLogger(Output));

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

Expand All @@ -34,8 +33,7 @@ public void TestSettingAndRevertingBackGuid()
public void TestPowerPlanShouldNotChange()
{
var userPlan = PowerManagementHelper.CurrentPlan;
var logger = new OutputLogger(Output);
var powerManagementApplier = new PowerManagementApplier(logger);
var powerManagementApplier = new PowerManagementApplier(new OutputLogger(Output));

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

Expand Down
3 changes: 1 addition & 2 deletions tests/BenchmarkDotNet.IntegrationTests/PriorityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public PriorityTests(ITestOutputHelper output) : base(output) { }
[Fact]
public void ParamsSupportPropertyWithPublicSetter()
{
var logger = new OutputLogger(Output);
var config = CreateSimpleConfig(logger);
var config = CreateSimpleConfig();

var summary = CanExecute<PriorityBenchmark>(config);
var columns = summary.Table.Columns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ public void SpecifiedProcessorArchitectureMustBeRespected()

private void Verify(Platform platform, Type benchmark)
{
var logger = new OutputLogger(Output);

var config = ManualConfig.CreateEmpty()
.AddJob(Job.Dry.WithPlatform(platform))
.AddLogger(logger); // make sure we get an output in the TestRunner log
.AddLogger(new OutputLogger(Output)); // make sure we get an output in the TestRunner log

// CanExecute ensures that at least one benchmark has executed successfully
CanExecute(benchmark, config, fullValidation: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public void CanExecuteWithNonDefaultUiCulture(string culture)
CultureInfo.CurrentCulture = overrideCulture;
CultureInfo.CurrentUICulture = overrideCulture;

var logger = new OutputLogger(Output);
var miniJob = Job.Dry.WithToolchain(RoslynToolchain.Instance);
var config = CreateSimpleConfig(logger, miniJob);
var config = CreateSimpleConfig(job: miniJob);

CanExecute<SimpleBenchmarks>(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ public SetupAndCleanupTests(ITestOutputHelper output) : base(output) { }
[Fact]
public void AllSetupAndCleanupMethodRunsForSpecificBenchmark()
{
var logger = new OutputLogger(Output);
var miniJob = Job.Default.WithStrategy(RunStrategy.Monitoring).WithWarmupCount(2).WithIterationCount(3).WithInvocationCount(1).WithUnrollFactor(1).WithId("MiniJob");
var config = CreateSimpleConfig(logger, miniJob);
var config = CreateSimpleConfig(job: miniJob);

var summary = CanExecute<Benchmarks>(config);
var standardOutput = GetCombinedStandardOutput(summary);
Expand Down

0 comments on commit 3906381

Please sign in to comment.