Skip to content

Commit

Permalink
Include additional OutputTargets from TestPackage in TestRunner (#351)
Browse files Browse the repository at this point in the history
* Include any additional OutputTargets specified by the TestPackage when the TestRunner creates a CompositeBenchmarkOutput

* Added unit test for verifying that additional output targets are included when writing to benchmark outputs

Co-authored-by: Aaron Stannard <[email protected]>
  • Loading branch information
taaaki and Aaronontheweb authored Aug 10, 2020
1 parent 999d79a commit 00905d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/NBench.Tests.End2End/NBenchIntregrationTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Petabridge <https://petabridge.com/>. All rights reserved.
// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -99,6 +100,19 @@ public void RunnerExcludePattern()
result.IgnoredTestsCount.Should().NotBe(0);
}

[Fact]
public void RunnerShouldIncludeAdditionalOutputTargets()
{
var testOutput = new TestBenchmarkOutput();

var package = LoadPackage();
package.Tracing = true;
package.AddOutput(testOutput);

TestRunner.Run(package);
testOutput.AdditionalOutputWasIncluded.Should().BeTrue("Expected inclusion of additional benchmark output, but was ignored.");
}

private static TestPackage LoadPackage(IEnumerable<string> include = null, IEnumerable<string> exclude = null)
{
var package = NBenchRunner.CreateTest<ConfigBenchmark>();
Expand All @@ -117,6 +131,23 @@ private static TestPackage LoadPackage(IEnumerable<string> include = null, IEnum

return package;
}

private class TestBenchmarkOutput : IBenchmarkOutput
{
public bool AdditionalOutputWasIncluded { get; set; } = false;

public TestBenchmarkOutput() { }

public void Error(Exception ex, string message) => AdditionalOutputWasIncluded = true;
public void Error(string message) => AdditionalOutputWasIncluded = true;
public void FinishBenchmark(string benchmarkName) => AdditionalOutputWasIncluded = true;
public void SkipBenchmark(string benchmarkName) => AdditionalOutputWasIncluded = true;
public void StartBenchmark(string benchmarkName) => AdditionalOutputWasIncluded = true;
public void Warning(string message) => AdditionalOutputWasIncluded = true;
public void WriteBenchmark(BenchmarkFinalResults results) => AdditionalOutputWasIncluded = true;
public void WriteLine(string message) => AdditionalOutputWasIncluded = true;
public void WriteRun(BenchmarkRunReport report, bool isWarmup = false) => AdditionalOutputWasIncluded = true;
}
}
}

2 changes: 2 additions & 0 deletions src/NBench/Sdk/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ protected virtual IBenchmarkOutput CreateOutput()
outputs.Add(new MarkdownBenchmarkOutput(_package.OutputDirectory));
}

outputs.AddRange(_package.OutputTargets);

return new CompositeBenchmarkOutput(outputs.ToArray());
}
}
Expand Down

0 comments on commit 00905d9

Please sign in to comment.