Skip to content

Commit

Permalink
Clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Feb 9, 2025
1 parent 01ee07d commit d606b4d
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions CliWrap.Tests/PipingSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,18 @@ public async Task I_can_execute_a_command_and_pipe_the_stdin_from_another_comman
public async Task I_can_execute_a_command_and_pipe_the_stdin_from_another_command_with_a_transform()
{
// Arrange
var cmdInput = Cli.Wrap(Dummy.Program.FilePath)
.WithArguments(["generate binary", "--length", "100000"]);

var cmd = Cli.Wrap(Dummy.Program.FilePath)
.WithArguments("length stdin")
.WithStandardInputPipe(
PipeSource.FromCommand(
cmdInput,
// Take only the first 5000 bytes
async (source, destination, cancellationToken) =>
{
using var buffer = MemoryPool<byte>.Shared.Rent(5000);

await source.ReadAtLeastAsync(
buffer.Memory,
5000,
false,
cancellationToken
);

await destination.WriteAsync(buffer.Memory[..5000], cancellationToken);
}
)
);
var cmd =
PipeSource.FromCommand(
Cli.Wrap(Dummy.Program.FilePath)
.WithArguments(["generate binary", "--length", "100000"]),
// Transform: take the first 5000 bytes and discard the rest
async (source, destination, cancellationToken) =>
{
using var buffer = MemoryPool<byte>.Shared.Rent(5000);
await source.ReadAtLeastAsync(buffer.Memory, 5000, false, cancellationToken);
await destination.WriteAsync(buffer.Memory[..5000], cancellationToken);
}
) | Cli.Wrap(Dummy.Program.FilePath).WithArguments("length stdin");

// Act
var result = await cmd.ExecuteBufferedAsync();
Expand Down

0 comments on commit d606b4d

Please sign in to comment.