Skip to content

Commit

Permalink
(cake-buildGH-1160) Specflow throws if intercepted process returns no…
Browse files Browse the repository at this point in the history
…n-zero
  • Loading branch information
bjorkstromm committed Oct 21, 2016
1 parent f7c8339 commit 41a5e9e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,79 @@ public void Should_Append_XsltFile()
"/xsltFile:\"/Working/template.xslt\"", result.Args);
}

[Fact]
public void Should_Rethrow_Exception_From_Action()
{
// Given
var exception = new CakeException("The exception message");
var fixture = new SpecFlowTestExecutionReporterFixture();
fixture.Settings.ThrowOnTestFailure = true;
var intercepting = true;

fixture.Action = context =>
{
context.ProcessRunner.Start(
new FilePath("/Working/tools/MSTest.exe"),
new ProcessSettings()
{
Arguments = "/resultsfile:\"/Working/TestResult.trx\""
});
// Quick fix to avoid throwing exception while intercepting action
if (intercepting)
{
intercepting = false;
}
else
{
throw exception;
}
};

// When
var result = Record.Exception(() => fixture.Run());

// Then
Assert.IsCakeException(result, exception.Message);
}

[Fact]
public void Should_Not_Rethrow_Exception_From_Action()
{
// Given
var exception = new CakeException("The exception message");
var fixture = new SpecFlowTestExecutionReporterFixture();
fixture.Settings.ThrowOnTestFailure = false;
var intercepting = true;

fixture.Action = context =>
{
var process = context.ProcessRunner.Start(
new FilePath("/Working/tools/MSTest.exe"),
new ProcessSettings()
{
Arguments = "/resultsfile:\"/Working/TestResult.trx\""
});
// Quick fix to avoid throwing exception while intercepting action
if (intercepting)
{
intercepting = false;
}
else
{
throw exception;
}
};

// When
var result = fixture.Run();

// Then
Assert.Equal("mstestexecutionreport \"/Working/Tests.csproj\" " +
"/testResult:\"/Working/TestResult.trx\"", result.Args);
}

[Fact]
public void Should_Capture_XUnit2()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ namespace Cake.Common.Tools.SpecFlow.TestExecutionReport
/// </summary>
public sealed class SpecFlowTestExecutionReportSettings : SpecFlowSettings
{
/// <summary>
/// Gets or sets a value indicating whether exceptions from the
/// intercepted action should be rethrown after report generation
/// </summary>
public bool ThrowOnTestFailure { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void Run(ICakeContext context,
var builder = GetArguments(interceptor, settings, projectFile);

// Execute the action
CakeException testException = null;
try
{
action(context);
Expand All @@ -77,10 +78,16 @@ public void Run(ICakeContext context,
{
// Write warning to log
context.Warning(e.Message);
testException = e;
}

// Run the tool.
Run(settings, builder);

if (settings.ThrowOnTestFailure && testException != null)
{
throw testException;
}
}

private static SpecFlowContext InterceptAction(
Expand Down

0 comments on commit 41a5e9e

Please sign in to comment.