Skip to content

Commit a455b5b

Browse files
committed
Make use of C# 14 features
1 parent ad07ade commit a455b5b

26 files changed

+542
-529
lines changed

CliWrap.Benchmarks/CliWrap.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageReference Include="BenchmarkDotNet" Version="0.15.5" />
8-
<PackageReference Include="CSharpier.MsBuild" Version="1.0.2" PrivateAssets="all" />
8+
<PackageReference Include="CSharpier.MsBuild" Version="1.2.1" PrivateAssets="all" />
99
<PackageReference Include="ProcessX" Version="1.5.6" />
1010
<PackageReference Include="RunProcessAsTask" Version="1.2.4" />
1111
<PackageReference Include="MedallionShell" Version="1.6.2" />

CliWrap.Signaler/CliWrap.Signaler.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>net35</TargetFramework>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageReference Include="CSharpier.MsBuild" Version="1.0.2" PrivateAssets="all" />
7+
<PackageReference Include="CSharpier.MsBuild" Version="1.2.1" PrivateAssets="all" />
8+
<PackageReference Include="PolyShim" Version="2.0.0" PrivateAssets="all" />
89
</ItemGroup>
910
</Project>

CliWrap.Tests.Dummy/CliWrap.Tests.Dummy.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageReference Include="CliFx" Version="2.3.6" />
8-
<PackageReference Include="CSharpier.MsBuild" Version="1.0.2" PrivateAssets="all" />
8+
<PackageReference Include="CSharpier.MsBuild" Version="1.2.1" PrivateAssets="all" />
99
</ItemGroup>
1010
</Project>

CliWrap.Tests/CancellationSpecs.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Reactive.Linq;
34
using System.Text;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using CliWrap.Buffered;
78
using CliWrap.EventStream;
8-
using CliWrap.Tests.Utils;
9+
using CliWrap.Tests.Utils.Extensions;
910
using FluentAssertions;
1011
using Xunit;
1112

@@ -32,7 +33,7 @@ public async Task I_can_execute_a_command_and_cancel_it_immediately()
3233
var ex = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => task);
3334
ex.CancellationToken.Should().Be(cts.Token);
3435

35-
ProcessEx.IsRunning(task.ProcessId).Should().BeFalse();
36+
Process.IsRunning(task.ProcessId).Should().BeFalse();
3637
stdOutBuffer.ToString().Should().NotContain("Done.");
3738
}
3839

@@ -55,7 +56,7 @@ public async Task I_can_execute_a_command_and_cancel_it_after_a_delay()
5556
var ex = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => task);
5657
ex.CancellationToken.Should().Be(cts.Token);
5758

58-
ProcessEx.IsRunning(task.ProcessId).Should().BeFalse();
59+
Process.IsRunning(task.ProcessId).Should().BeFalse();
5960
stdOutBuffer.ToString().Should().NotContain("Done.");
6061
}
6162

@@ -87,7 +88,7 @@ public async Task I_can_execute_a_command_and_cancel_it_gracefully_after_a_delay
8788
var ex = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => task);
8889
ex.CancellationToken.Should().Be(cts.Token);
8990

90-
ProcessEx.IsRunning(task.ProcessId).Should().BeFalse();
91+
Process.IsRunning(task.ProcessId).Should().BeFalse();
9192
stdOutBuffer.ToString().Should().Contain("Canceled.").And.NotContain("Done.");
9293
}
9394

CliWrap.Tests/CliWrap.Tests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
</ItemGroup>
88
<ItemGroup>
99
<PackageReference Include="coverlet.collector" Version="6.0.4" PrivateAssets="all" />
10-
<PackageReference Include="CSharpier.MsBuild" Version="1.0.2" PrivateAssets="all" />
10+
<PackageReference Include="CSharpier.MsBuild" Version="1.2.1" PrivateAssets="all" />
1111
<PackageReference Include="FluentAssertions" Version="8.8.0" />
1212
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="all" />
1313
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
14-
<PackageReference Include="PolyShim" Version="1.15.0" PrivateAssets="all" />
1514
<PackageReference Include="System.Reactive" Version="6.1.0" />
1615
<PackageReference Include="xunit" Version="2.9.3" />
1716
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" PrivateAssets="all" />

CliWrap.Tests/EnvironmentSpecs.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public async Task I_can_execute_a_command_with_some_environment_variables_overwr
5454
var variableToOverwrite = $"CLIWRAP_TEST_OVERWRITE_{key}";
5555
var variableToUnset = $"CLIWRAP_TEST_UNSET_{key}";
5656

57-
using (TempEnvironmentVariable.Set(variableToKeep, "keep")) // will be left unchanged
58-
using (TempEnvironmentVariable.Set(variableToOverwrite, "overwrite")) // will be overwritten
59-
using (TempEnvironmentVariable.Set(variableToUnset, "unset")) // will be unset
57+
using (Environment.SetTempEnvironmentVariable(variableToKeep, "keep")) // will be left unchanged
58+
using (Environment.SetTempEnvironmentVariable(variableToOverwrite, "overwrite")) // will be overwritten
59+
using (Environment.SetTempEnvironmentVariable(variableToUnset, "unset")) // will be unset
6060
{
6161
var cmd = Cli.Wrap(Dummy.Program.FilePath)
6262
.WithArguments(["env", variableToKeep, variableToOverwrite, variableToUnset])

CliWrap.Tests/PathResolutionSpecs.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using System;
12
using System.IO;
23
using System.Runtime.InteropServices;
34
using System.Threading.Tasks;
45
using CliWrap.Buffered;
56
using CliWrap.Tests.Utils;
7+
using CliWrap.Tests.Utils.Extensions;
68
using FluentAssertions;
79
using Xunit;
810

@@ -34,9 +36,9 @@ public async Task I_can_execute_a_command_on_a_script_using_its_short_name()
3436

3537
// Arrange
3638
using var dir = TempDir.Create();
37-
File.WriteAllText(Path.Combine(dir.Path, "test-script.cmd"), "@echo hello");
39+
await File.WriteAllTextAsync(Path.Combine(dir.Path, "test-script.cmd"), "@echo hello");
3840

39-
using (TempEnvironmentVariable.ExtendPath(dir.Path))
41+
using (Environment.ExtendPath(dir.Path))
4042
{
4143
var cmd = Cli.Wrap("test-script");
4244

CliWrap.Tests/PipingSpecs.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public async Task I_can_execute_a_command_and_pipe_the_stdin_from_a_file()
6666
{
6767
// Arrange
6868
using var file = TempFile.Create();
69-
File.WriteAllText(file.Path, "Hello world!");
69+
await File.WriteAllTextAsync(file.Path, "Hello world!");
7070

7171
var cmd =
7272
PipeSource.FromFile(file.Path)
@@ -547,16 +547,14 @@ public async Task I_can_execute_a_command_and_pipe_the_stdout_into_multiple_stre
547547

548548
// Arrange
549549
var cmd = Cli.Wrap(Dummy.Program.FilePath)
550-
.WithArguments(
551-
[
552-
"generate binary",
553-
"--length",
554-
"1000000",
555-
// Buffer needs to be >= BufferSizes.Stream to fail
556-
"--buffer",
557-
"100000",
558-
]
559-
);
550+
.WithArguments([
551+
"generate binary",
552+
"--length",
553+
"1000000",
554+
// Buffer needs to be >= BufferSizes.Stream to fail
555+
"--buffer",
556+
"100000",
557+
]);
560558

561559
// Act
562560
using var mergedStream1 = new MemoryStream();

CliWrap.Tests/Utils/Extensions/AssertionExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ namespace CliWrap.Tests.Utils.Extensions;
77

88
internal static class AssertionExtensions
99
{
10-
public static void ConsistOfLines(
11-
this StringAssertions assertions,
12-
params IEnumerable<string> lines
13-
) =>
14-
assertions
15-
.Subject.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
16-
.Should()
17-
.Equal(lines);
10+
extension(StringAssertions assertions)
11+
{
12+
public void ConsistOfLines(params IEnumerable<string> lines) =>
13+
assertions
14+
.Subject.Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries)
15+
.Should()
16+
.Equal(lines);
17+
}
1818
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.IO;
3+
using System.Reactive.Disposables;
4+
5+
namespace CliWrap.Tests.Utils.Extensions;
6+
7+
internal static class EnvironmentExtensions
8+
{
9+
extension(Environment)
10+
{
11+
public static IDisposable SetTempEnvironmentVariable(string name, string? value)
12+
{
13+
var lastValue = Environment.GetEnvironmentVariable(name);
14+
Environment.SetEnvironmentVariable(name, value);
15+
16+
return Disposable.Create(() => Environment.SetEnvironmentVariable(name, lastValue));
17+
}
18+
19+
public static IDisposable ExtendPath(string path) =>
20+
SetTempEnvironmentVariable(
21+
"PATH",
22+
Environment.GetEnvironmentVariable("PATH") + Path.PathSeparator + path
23+
);
24+
}
25+
}

0 commit comments

Comments
 (0)