mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Run test dummy through the app host
This commit is contained in:
@@ -1,19 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace CliFx.Tests.Dummy;
|
namespace CliFx.Tests.Dummy;
|
||||||
|
|
||||||
// This dummy application is used in tests for scenarios that require an external process to properly verify
|
// This dummy application is used in tests for scenarios that require an external process to properly verify
|
||||||
public static partial class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
public static Assembly Assembly { get; } = Assembly.GetExecutingAssembly();
|
// Path to the apphost
|
||||||
|
public static string FilePath { get; } = Path.ChangeExtension(
|
||||||
|
Assembly.GetExecutingAssembly().Location,
|
||||||
|
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "exe" : null
|
||||||
|
);
|
||||||
|
|
||||||
public static string Location { get; } = Assembly.Location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static partial class Program
|
|
||||||
{
|
|
||||||
public static async Task Main()
|
public static async Task Main()
|
||||||
{
|
{
|
||||||
// Make sure color codes are not produced because we rely on the output in tests
|
// Make sure color codes are not produced because we rely on the output in tests
|
||||||
|
|||||||
@@ -41,11 +41,9 @@ public class CancellationSpecs : SpecsBase
|
|||||||
PipeTarget.ToStringBuilder(stdOutBuffer)
|
PipeTarget.ToStringBuilder(stdOutBuffer)
|
||||||
);
|
);
|
||||||
|
|
||||||
var command = Cli.Wrap("dotnet")
|
var command =
|
||||||
.WithArguments(a => a
|
Cli.Wrap(Dummy.Program.FilePath).WithArguments("cancel-test") |
|
||||||
.Add(Dummy.Program.Location)
|
pipeTarget;
|
||||||
.Add("cancel-test")
|
|
||||||
) | pipeTarget;
|
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () =>
|
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () =>
|
||||||
|
|||||||
@@ -27,11 +27,9 @@ public class ConsoleSpecs : SpecsBase
|
|||||||
// Can't verify our own console output, so using an external process for this test
|
// Can't verify our own console output, so using an external process for this test
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
var command = "Hello world" | Cli.Wrap("dotnet")
|
var command =
|
||||||
.WithArguments(a => a
|
"Hello world" |
|
||||||
.Add(Dummy.Program.Location)
|
Cli.Wrap(Dummy.Program.FilePath).WithArguments("console-test");
|
||||||
.Add("console-test")
|
|
||||||
);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await command.ExecuteBufferedAsync();
|
var result = await command.ExecuteBufferedAsync();
|
||||||
|
|||||||
@@ -32,11 +32,9 @@ public class DirectivesSpecs : SpecsBase
|
|||||||
cts.Cancel();
|
cts.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
var command = Cli.Wrap("dotnet")
|
var command =
|
||||||
.WithArguments(a => a
|
Cli.Wrap(Dummy.Program.FilePath).WithArguments("[debug]") |
|
||||||
.Add(Dummy.Program.Location)
|
HandleStdOut;
|
||||||
.Add("[debug]")
|
|
||||||
) | HandleStdOut;
|
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -169,11 +169,8 @@ public class EnvironmentSpecs : SpecsBase
|
|||||||
// System.Environment when they are not provided explicitly to CliApplication.
|
// System.Environment when they are not provided explicitly to CliApplication.
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
var command = Cli.Wrap("dotnet")
|
var command = Cli.Wrap(Dummy.Program.FilePath)
|
||||||
.WithArguments(a => a
|
.WithArguments("env-test")
|
||||||
.Add(Dummy.Program.Location)
|
|
||||||
.Add("env-test")
|
|
||||||
)
|
|
||||||
.WithEnvironmentVariables(e => e
|
.WithEnvironmentVariables(e => e
|
||||||
.Set("ENV_TARGET", "Mars")
|
.Set("ENV_TARGET", "Mars")
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user