build: initial project release
Some checks failed
default / dotnet-default-workflow (push) Failing after 54s
Some checks failed
default / dotnet-default-workflow (push) Failing after 54s
This commit is contained in:
commit
1e4687aff6
59 changed files with 4902 additions and 0 deletions
58
src/process.tests/ValidationTests.cs
Normal file
58
src/process.tests/ValidationTests.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using Geekeey.Process.Buffered;
|
||||
|
||||
namespace Geekeey.Process.Tests;
|
||||
|
||||
internal sealed class ValidationTests
|
||||
{
|
||||
private static Command Exit()
|
||||
{
|
||||
return new Command(Testing.Fixture.Program.FilePath)
|
||||
.WithArguments(["exit", "1"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_try_to_execute_a_command_and_get_an_error_if_it_returns_a_non_zero_exit_code()
|
||||
{
|
||||
// Arrange
|
||||
var cmd = Exit();
|
||||
|
||||
// Act & Assert
|
||||
await Assert.That(async () => await cmd.ExecuteAsync()).Throws<CommandExecutionException>().And
|
||||
.Member(static exception => exception.Message, static source => source.Contains("a non-zero exit code (1)")).And
|
||||
.Member(static exception => exception.ExitCode, static source => source.IsEqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_try_to_execute_a_command_with_buffering_and_get_a_detailed_error_if_it_returns_a_non_zero_exit_code()
|
||||
{
|
||||
// Arrange
|
||||
var cmd = Exit();
|
||||
|
||||
|
||||
// Act & Assert
|
||||
await Assert.That(async () => await cmd.ExecuteBufferedAsync()).Throws<CommandExecutionException>().And
|
||||
.Member(static exception => exception.Message, static source => source.Contains("Exit code set to 1")).And
|
||||
.Member(static exception => exception.ExitCode, static source => source.IsEqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_execute_a_command_without_validating_the_exit_code()
|
||||
{
|
||||
// Arrange
|
||||
var cmd = Exit()
|
||||
.WithExitValidation(ValidationMode.None);
|
||||
|
||||
// Act
|
||||
var result = await cmd.ExecuteAsync();
|
||||
|
||||
// Assert
|
||||
using (Assert.Multiple())
|
||||
{
|
||||
await Assert.That(result.ExitCode).IsEqualTo(1);
|
||||
await Assert.That(result.IsSuccess).IsFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue