Skip to content

Commit 9d7bb56

Browse files
authored
Merge pull request #753 from adamralph/xunit3-fix
fix switch to xunit 3
2 parents 1acc7d5 + 25dba56 commit 9d7bb56

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

SimpleExecTests/EchoingCommands.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace SimpleExecTests;
77

88
public static class EchoingCommands
99
{
10-
private static readonly CancellationToken ct = TestContext.Current.CancellationToken;
10+
private static CancellationToken Ct => TestContext.Current.CancellationToken;
1111

1212
[Fact]
1313
public static void EchoingACommand()
@@ -16,7 +16,7 @@ public static void EchoingACommand()
1616
Console.SetOut(Capture.Out);
1717

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

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

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

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

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

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

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

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

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

8080
// assert
8181
var error = Capture.Out.ToString()!;

SimpleExecTests/ExitCodes.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SimpleExecTests;
66

77
public static class ExitCodes
88
{
9-
private static readonly CancellationToken ct = TestContext.Current.CancellationToken;
9+
private static CancellationToken Ct => TestContext.Current.CancellationToken;
1010

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

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

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

6060
// assert
6161
if (shouldThrow)

SimpleExecTests/ReadingCommands.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace SimpleExecTests;
88

99
public static class ReadingCommands
1010
{
11-
private static readonly CancellationToken ct = TestContext.Current.CancellationToken;
11+
private static CancellationToken Ct => TestContext.Current.CancellationToken;
1212

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

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

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

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

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

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

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

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

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

115115
// assert
116116
Assert.Equal(nameof(name), Assert.IsType<ArgumentException>(exception).ParamName);

SimpleExecTests/RunningCommands.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ namespace SimpleExecTests;
1010
public static class RunningCommands
1111
{
1212
private static readonly string command = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "hello-world.cmd" : "ls";
13-
private static readonly CancellationToken ct = TestContext.Current.CancellationToken;
13+
private static CancellationToken Ct => TestContext.Current.CancellationToken;
1414

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

1717
[Fact]
1818
public static void RunningASucceedingCommand()
1919
{
2020
// act
21-
var exception = Record.Exception(() => Command.Run(command, cancellationToken: ct));
21+
var exception = Record.Exception(() => Command.Run(command, cancellationToken: Ct));
2222

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

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

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

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

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

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

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

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

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

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

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

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

152152
Environment.SetEnvironmentVariable(
153153
"PATH",
154154
$"{Environment.GetEnvironmentVariable("PATH")}{Path.PathSeparator}{directory}",
155155
EnvironmentVariableTarget.Process);
156156

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

160160
// assert
161161
Assert.Null(exception);
@@ -183,10 +183,10 @@ public static async Task RunningCommandsInPathOnWindowsWithSpecificPathExt(
183183

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

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

191191
Environment.SetEnvironmentVariable(
192192
"PATH",
@@ -199,7 +199,7 @@ public static async Task RunningCommandsInPathOnWindowsWithSpecificPathExt(
199199
EnvironmentVariableTarget.Process);
200200

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

204204
// assert
205205
Assert.Equal(expected, actual);

0 commit comments

Comments
 (0)