Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions SimpleExecTests/EchoingCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SimpleExecTests;

public static class EchoingCommands
{
private static readonly CancellationToken ct = TestContext.Current.CancellationToken;
private static CancellationToken Ct => TestContext.Current.CancellationToken;

[Fact]
public static void EchoingACommand()
Expand All @@ -16,7 +16,7 @@ public static void EchoingACommand()
Console.SetOut(Capture.Out);

// act
Command.Run("dotnet", $"exec {Tester.Path} {TestName()}", cancellationToken: ct);
Command.Run("dotnet", $"exec {Tester.Path} {TestName()}", cancellationToken: Ct);

// assert
Assert.Contains(TestName(), Capture.Out.ToString()!, StringComparison.Ordinal);
Expand All @@ -29,7 +29,7 @@ public static void EchoingACommandWithAnArgList()
Console.SetOut(Capture.Out);

// act
Command.Run("dotnet", ["exec", Tester.Path, "he llo", "\"world \"today\"",], cancellationToken: ct);
Command.Run("dotnet", ["exec", Tester.Path, "he llo", "\"world \"today\"",], cancellationToken: Ct);

// assert
var lines = Capture.Out.ToString()!.Split('\r', '\n').ToList();
Expand All @@ -46,7 +46,7 @@ public static void SuppressingCommandEcho()
Console.SetOut(Capture.Out);

// act
Command.Run("dotnet", $"exec {Tester.Path} {TestName()}", noEcho: true, cancellationToken: ct);
Command.Run("dotnet", $"exec {Tester.Path} {TestName()}", noEcho: true, cancellationToken: Ct);

// assert
Assert.DoesNotContain(TestName(), Capture.Out.ToString()!, StringComparison.Ordinal);
Expand All @@ -59,7 +59,7 @@ public static void EchoingACommandWithASpecificPrefix()
Console.SetOut(Capture.Out);

// act
Command.Run("dotnet", $"exec {Tester.Path} {TestName()}", noEcho: false, echoPrefix: $"{TestName()} prefix", cancellationToken: ct);
Command.Run("dotnet", $"exec {Tester.Path} {TestName()}", noEcho: false, echoPrefix: $"{TestName()} prefix", cancellationToken: Ct);

// assert
var error = Capture.Out.ToString()!;
Expand All @@ -75,7 +75,7 @@ public static void SuppressingCommandEchoWithASpecificPrefix()
Console.SetOut(Capture.Out);

// act
Command.Run("dotnet", $"exec {Tester.Path} {TestName()}", noEcho: true, echoPrefix: $"{TestName()} prefix", cancellationToken: ct);
Command.Run("dotnet", $"exec {Tester.Path} {TestName()}", noEcho: true, echoPrefix: $"{TestName()} prefix", cancellationToken: Ct);

// assert
var error = Capture.Out.ToString()!;
Expand Down
8 changes: 4 additions & 4 deletions SimpleExecTests/ExitCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SimpleExecTests;

public static class ExitCodes
{
private static readonly CancellationToken ct = TestContext.Current.CancellationToken;
private static CancellationToken Ct => TestContext.Current.CancellationToken;

[Theory]
[InlineData(0, false)]
Expand All @@ -15,7 +15,7 @@ public static class ExitCodes
public static void RunningACommand(int exitCode, bool shouldThrow)
{
// act
var exception = Record.Exception(() => Command.Run("dotnet", $"exec {Tester.Path} {exitCode}", handleExitCode: code => code == 1, cancellationToken: ct));
var exception = Record.Exception(() => Command.Run("dotnet", $"exec {Tester.Path} {exitCode}", handleExitCode: code => code == 1, cancellationToken: Ct));

// assert
if (shouldThrow)
Expand All @@ -35,7 +35,7 @@ public static void RunningACommand(int exitCode, bool shouldThrow)
public static async Task RunningACommandAsync(int exitCode, bool shouldThrow)
{
// act
var exception = await Record.ExceptionAsync(() => Command.RunAsync("dotnet", $"exec {Tester.Path} {exitCode}", handleExitCode: code => code == 1, cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.RunAsync("dotnet", $"exec {Tester.Path} {exitCode}", handleExitCode: code => code == 1, cancellationToken: Ct));

// assert
if (shouldThrow)
Expand All @@ -55,7 +55,7 @@ public static async Task RunningACommandAsync(int exitCode, bool shouldThrow)
public static async Task ReadingACommandAsync(int exitCode, bool shouldThrow)
{
// act
var exception = await Record.ExceptionAsync(async () => _ = await Command.ReadAsync("dotnet", $"exec {Tester.Path} {exitCode}", handleExitCode: code => code == 1, cancellationToken: ct));
var exception = await Record.ExceptionAsync(async () => _ = await Command.ReadAsync("dotnet", $"exec {Tester.Path} {exitCode}", handleExitCode: code => code == 1, cancellationToken: Ct));

// assert
if (shouldThrow)
Expand Down
18 changes: 9 additions & 9 deletions SimpleExecTests/ReadingCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace SimpleExecTests;

public static class ReadingCommands
{
private static readonly CancellationToken ct = TestContext.Current.CancellationToken;
private static CancellationToken Ct => TestContext.Current.CancellationToken;

[Theory]
[InlineData(false)]
[InlineData(true)]
public static async Task ReadingACommandAsync(bool largeOutput)
{
// act
var (standardOutput, standardError) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world" + (largeOutput ? " large" : ""), cancellationToken: ct);
var (standardOutput, standardError) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world" + (largeOutput ? " large" : ""), cancellationToken: Ct);

// assert
Assert.Contains("hello world", standardOutput, StringComparison.Ordinal);
Expand All @@ -36,7 +36,7 @@ public static async Task ReadingACommandAsyncWithAnArgList(bool largeOutput)
}

// act
var (standardOutput, standardError) = await Command.ReadAsync("dotnet", args, cancellationToken: ct);
var (standardOutput, standardError) = await Command.ReadAsync("dotnet", args, cancellationToken: Ct);

// assert
Assert.Contains(largeOutput ? "Arg count: 3" : "Arg count: 2", standardOutput, StringComparison.Ordinal);
Expand All @@ -50,7 +50,7 @@ public static async Task ReadingACommandAsyncWithAnArgList(bool largeOutput)
public static async Task ReadingACommandWithInputAsync(bool largeOutput)
{
// act
var (standardOutput, standardError) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world in" + (largeOutput ? " large" : ""), standardInput: "this is input", cancellationToken: ct);
var (standardOutput, standardError) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world in" + (largeOutput ? " large" : ""), standardInput: "this is input", cancellationToken: Ct);

// assert
Assert.Contains("hello world", standardOutput, StringComparison.Ordinal);
Expand All @@ -64,7 +64,7 @@ public static async Task ReadingACommandWithInputAsync(bool largeOutput)
public static async Task ReadingAUnicodeCommandAsync(bool largeOutput)
{
// act
var (standardOutput, standardError) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world unicode" + (largeOutput ? " large" : ""), encoding: new UnicodeEncoding(), cancellationToken: ct);
var (standardOutput, standardError) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world unicode" + (largeOutput ? " large" : ""), encoding: new UnicodeEncoding(), cancellationToken: Ct);

// assert
Assert.Contains("Pi (\u03a0)", standardOutput, StringComparison.Ordinal);
Expand All @@ -75,7 +75,7 @@ public static async Task ReadingAUnicodeCommandAsync(bool largeOutput)
public static async Task ReadingAFailingCommandAsync()
{
// act
var exception = await Record.ExceptionAsync(() => Command.ReadAsync("dotnet", $"exec {Tester.Path} 1 hello world", cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.ReadAsync("dotnet", $"exec {Tester.Path} 1 hello world", cancellationToken: Ct));

// assert
var exitCodeReadException = Assert.IsType<ExitCodeReadException>(exception);
Expand All @@ -88,7 +88,7 @@ public static async Task ReadingAFailingCommandAsync()
public static async Task ReadingACommandAsyncInANonExistentWorkDirectory()
{
// act
var exception = await Record.ExceptionAsync(() => Command.ReadAsync("dotnet", $"exec {Tester.Path}", "non-existent-working-directory", cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.ReadAsync("dotnet", $"exec {Tester.Path}", "non-existent-working-directory", cancellationToken: Ct));

// assert
_ = Assert.IsType<Win32Exception>(exception);
Expand All @@ -98,7 +98,7 @@ public static async Task ReadingACommandAsyncInANonExistentWorkDirectory()
public static async Task ReadingANonExistentCommandAsync()
{
// act
var exception = await Record.ExceptionAsync(() => Command.ReadAsync("simple-exec-tests-non-existent-command", cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.ReadAsync("simple-exec-tests-non-existent-command", cancellationToken: Ct));

// assert
_ = Assert.IsType<Win32Exception>(exception);
Expand All @@ -110,7 +110,7 @@ public static async Task ReadingANonExistentCommandAsync()
public static async Task ReadingNoCommandAsync(string name)
{
// act
var exception = await Record.ExceptionAsync(() => Command.ReadAsync(name, cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.ReadAsync(name, cancellationToken: Ct));

// assert
Assert.Equal(nameof(name), Assert.IsType<ArgumentException>(exception).ParamName);
Expand Down
34 changes: 17 additions & 17 deletions SimpleExecTests/RunningCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ namespace SimpleExecTests;
public static class RunningCommands
{
private static readonly string command = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "hello-world.cmd" : "ls";
private static readonly CancellationToken ct = TestContext.Current.CancellationToken;
private static CancellationToken Ct => TestContext.Current.CancellationToken;

public static bool OsPlatformIsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

[Fact]
public static void RunningASucceedingCommand()
{
// act
var exception = Record.Exception(() => Command.Run(command, cancellationToken: ct));
var exception = Record.Exception(() => Command.Run(command, cancellationToken: Ct));

// assert
Assert.Null(exception);
Expand All @@ -28,7 +28,7 @@ public static void RunningASucceedingCommand()
public static void RunningASucceedingCommandWithArgs()
{
// act
var exception = Record.Exception(() => Command.Run("dotnet", $"exec {Tester.Path} hello world", cancellationToken: ct));
var exception = Record.Exception(() => Command.Run("dotnet", $"exec {Tester.Path} hello world", cancellationToken: Ct));

// assert
Assert.Null(exception);
Expand All @@ -38,7 +38,7 @@ public static void RunningASucceedingCommandWithArgs()
public static async Task RunningASucceedingCommandAsync()
{
// act
var exception = await Record.ExceptionAsync(() => Command.RunAsync(command, cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.RunAsync(command, cancellationToken: Ct));

// assert
Assert.Null(exception);
Expand All @@ -48,7 +48,7 @@ public static async Task RunningASucceedingCommandAsync()
public static void RunningAFailingCommand()
{
// act
var exception = Record.Exception(() => Command.Run("dotnet", $"exec {Tester.Path} 1 hello world", cancellationToken: ct));
var exception = Record.Exception(() => Command.Run("dotnet", $"exec {Tester.Path} 1 hello world", cancellationToken: Ct));

// assert
Assert.Equal(1, Assert.IsType<ExitCodeException>(exception).ExitCode);
Expand All @@ -58,7 +58,7 @@ public static void RunningAFailingCommand()
public static async Task RunningAFailingCommandAsync()
{
// act
var exception = await Record.ExceptionAsync(() => Command.RunAsync("dotnet", $"exec {Tester.Path} 1 hello world", cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.RunAsync("dotnet", $"exec {Tester.Path} 1 hello world", cancellationToken: Ct));

// assert
Assert.Equal(1, Assert.IsType<ExitCodeException>(exception).ExitCode);
Expand All @@ -68,7 +68,7 @@ public static async Task RunningAFailingCommandAsync()
public static void RunningACommandInANonExistentWorkDirectory()
{
// act
var exception = Record.Exception(() => Command.Run("dotnet", $"exec {Tester.Path}", "non-existent-working-directory", cancellationToken: ct));
var exception = Record.Exception(() => Command.Run("dotnet", $"exec {Tester.Path}", "non-existent-working-directory", cancellationToken: Ct));

// assert
_ = Assert.IsType<Win32Exception>(exception);
Expand All @@ -78,7 +78,7 @@ public static void RunningACommandInANonExistentWorkDirectory()
public static async Task RunningACommandAsyncInANonExistentWorkDirectory()
{
// act
var exception = await Record.ExceptionAsync(() => Command.RunAsync("dotnet", $"exec {Tester.Path}", "non-existent-working-directory", cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.RunAsync("dotnet", $"exec {Tester.Path}", "non-existent-working-directory", cancellationToken: Ct));

// assert
_ = Assert.IsType<Win32Exception>(exception);
Expand All @@ -88,7 +88,7 @@ public static async Task RunningACommandAsyncInANonExistentWorkDirectory()
public static void RunningANonExistentCommand()
{
// act
var exception = Record.Exception(() => Command.Run("simple-exec-tests-non-existent-command", cancellationToken: ct));
var exception = Record.Exception(() => Command.Run("simple-exec-tests-non-existent-command", cancellationToken: Ct));

// assert
_ = Assert.IsType<Win32Exception>(exception);
Expand All @@ -98,7 +98,7 @@ public static void RunningANonExistentCommand()
public static async Task RunningANonExistentCommandAsync()
{
// act
var exception = await Record.ExceptionAsync(() => Command.RunAsync("simple-exec-tests-non-existent-command", cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.RunAsync("simple-exec-tests-non-existent-command", cancellationToken: Ct));

// assert
_ = Assert.IsType<Win32Exception>(exception);
Expand All @@ -110,7 +110,7 @@ public static async Task RunningANonExistentCommandAsync()
public static void RunningNoCommand(string name)
{
// act
var exception = Record.Exception(() => Command.Run(name, cancellationToken: ct));
var exception = Record.Exception(() => Command.Run(name, cancellationToken: Ct));

// assert
Assert.Equal(nameof(name), Assert.IsType<ArgumentException>(exception).ParamName);
Expand All @@ -122,7 +122,7 @@ public static void RunningNoCommand(string name)
public static async Task RunningNoCommandAsync(string name)
{
// act
var exception = await Record.ExceptionAsync(() => Command.RunAsync(name, cancellationToken: ct));
var exception = await Record.ExceptionAsync(() => Command.RunAsync(name, cancellationToken: Ct));

// assert
Assert.Equal(nameof(name), Assert.IsType<ArgumentException>(exception).ParamName);
Expand All @@ -147,15 +147,15 @@ public static async Task RunningCommandsInPathOnWindows()

var name = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
var fullName = Path.Combine(directory, Path.ChangeExtension(name, "cmd"));
await File.WriteAllTextAsync(fullName, "echo foo", cancellationToken: ct);
await File.WriteAllTextAsync(fullName, "echo foo", cancellationToken: Ct);

Environment.SetEnvironmentVariable(
"PATH",
$"{Environment.GetEnvironmentVariable("PATH")}{Path.PathSeparator}{directory}",
EnvironmentVariableTarget.Process);

// act
var exception = Record.Exception(() => Command.Run(name, cancellationToken: ct));
var exception = Record.Exception(() => Command.Run(name, cancellationToken: Ct));

// assert
Assert.Null(exception);
Expand Down Expand Up @@ -183,10 +183,10 @@ public static async Task RunningCommandsInPathOnWindowsWithSpecificPathExt(

var name = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
var batName = Path.Combine(directory, Path.ChangeExtension(name, "bat"));
await File.WriteAllTextAsync(batName, "@echo hello from bat", cancellationToken: ct);
await File.WriteAllTextAsync(batName, "@echo hello from bat", cancellationToken: Ct);

var cmdName = Path.Combine(directory, Path.ChangeExtension(name, "cmd"));
await File.WriteAllTextAsync(cmdName, "@echo hello from cmd", cancellationToken: ct);
await File.WriteAllTextAsync(cmdName, "@echo hello from cmd", cancellationToken: Ct);

Environment.SetEnvironmentVariable(
"PATH",
Expand All @@ -199,7 +199,7 @@ public static async Task RunningCommandsInPathOnWindowsWithSpecificPathExt(
EnvironmentVariableTarget.Process);

// act
var actual = (await Command.ReadAsync(name, cancellationToken: ct)).StandardOutput.Trim();
var actual = (await Command.ReadAsync(name, cancellationToken: Ct)).StandardOutput.Trim();

// assert
Assert.Equal(expected, actual);
Expand Down
Loading