Skip to content

Commit

Permalink
Add IgnoreExitCode to ToolSettings
Browse files Browse the repository at this point in the history
- When true, then ProcessExitCode method is not called
  • Loading branch information
flcdrg authored and devlead committed Sep 7, 2020
1 parent e3d84fd commit a073a71
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Cake.Core.Tests/Unit/Tooling/ToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ public void Should_Throw_On_Invalid_ExitCode_Validated_By_Custom_Validator()
// Then
AssertEx.IsCakeException(result, "UnitTest");
}

[Fact]
public void Should_Not_Throw_On_Invalid_ExitCode_When_IgnoreExitCode_Is_True()
{
// Given
var fixture = new DummyToolFixture();
fixture.Settings.IgnoreExitCode = true;
fixture.GivenProcessExitsWithCode(10);

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

// Then
Assert.IsNotType<Exception>(result);
}
}
}
}
5 changes: 4 additions & 1 deletion src/Cake.Core/Tooling/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ protected void Run(
// Post action specified?
postAction?.Invoke(process);

ProcessExitCode(process.GetExitCode());
if (!settings.IgnoreExitCode)
{
ProcessExitCode(process.GetExitCode());
}
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions src/Cake.Core/Tooling/ToolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,17 @@ public class ToolSettings
/// </code>
/// </example>
public IDictionary<string, string> EnvironmentVariables { get; set; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// Gets or sets a value indicating whether the exit code from the tool process causes an exception to be thrown.
/// </summary>
/// <example>
/// <code>
/// DotNetCoreTest("MyProject.csproj", new DotNetCoreTestSettings {
/// IgnoreExitCode = true
/// });
/// </code>
/// </example>
public bool IgnoreExitCode { get; set; }
}
}

0 comments on commit a073a71

Please sign in to comment.