From c95b6c32d5d43a2ced293a1466b443a939a32e7d Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:55:37 +0300 Subject: [PATCH] Run test dummy through the app host --- CliFx.Tests.Dummy/Program.cs | 15 ++++++++------- CliFx.Tests/CancellationSpecs.cs | 8 +++----- CliFx.Tests/ConsoleSpecs.cs | 8 +++----- CliFx.Tests/DirectivesSpecs.cs | 8 +++----- CliFx.Tests/EnvironmentSpecs.cs | 7 ++----- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/CliFx.Tests.Dummy/Program.cs b/CliFx.Tests.Dummy/Program.cs index 04059cc..ea48a82 100644 --- a/CliFx.Tests.Dummy/Program.cs +++ b/CliFx.Tests.Dummy/Program.cs @@ -1,19 +1,20 @@ using System; +using System.IO; using System.Reflection; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace CliFx.Tests.Dummy; // 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() { // Make sure color codes are not produced because we rely on the output in tests diff --git a/CliFx.Tests/CancellationSpecs.cs b/CliFx.Tests/CancellationSpecs.cs index e6cd25f..32e6e18 100644 --- a/CliFx.Tests/CancellationSpecs.cs +++ b/CliFx.Tests/CancellationSpecs.cs @@ -41,11 +41,9 @@ public class CancellationSpecs : SpecsBase PipeTarget.ToStringBuilder(stdOutBuffer) ); - var command = Cli.Wrap("dotnet") - .WithArguments(a => a - .Add(Dummy.Program.Location) - .Add("cancel-test") - ) | pipeTarget; + var command = + Cli.Wrap(Dummy.Program.FilePath).WithArguments("cancel-test") | + pipeTarget; // Act & assert await Assert.ThrowsAnyAsync(async () => diff --git a/CliFx.Tests/ConsoleSpecs.cs b/CliFx.Tests/ConsoleSpecs.cs index 6e48bc8..b6d3429 100644 --- a/CliFx.Tests/ConsoleSpecs.cs +++ b/CliFx.Tests/ConsoleSpecs.cs @@ -27,11 +27,9 @@ public class ConsoleSpecs : SpecsBase // Can't verify our own console output, so using an external process for this test // Arrange - var command = "Hello world" | Cli.Wrap("dotnet") - .WithArguments(a => a - .Add(Dummy.Program.Location) - .Add("console-test") - ); + var command = + "Hello world" | + Cli.Wrap(Dummy.Program.FilePath).WithArguments("console-test"); // Act var result = await command.ExecuteBufferedAsync(); diff --git a/CliFx.Tests/DirectivesSpecs.cs b/CliFx.Tests/DirectivesSpecs.cs index ec0d61b..327650d 100644 --- a/CliFx.Tests/DirectivesSpecs.cs +++ b/CliFx.Tests/DirectivesSpecs.cs @@ -32,11 +32,9 @@ public class DirectivesSpecs : SpecsBase cts.Cancel(); } - var command = Cli.Wrap("dotnet") - .WithArguments(a => a - .Add(Dummy.Program.Location) - .Add("[debug]") - ) | HandleStdOut; + var command = + Cli.Wrap(Dummy.Program.FilePath).WithArguments("[debug]") | + HandleStdOut; // Act & assert try diff --git a/CliFx.Tests/EnvironmentSpecs.cs b/CliFx.Tests/EnvironmentSpecs.cs index d269955..4180640 100644 --- a/CliFx.Tests/EnvironmentSpecs.cs +++ b/CliFx.Tests/EnvironmentSpecs.cs @@ -169,11 +169,8 @@ public class EnvironmentSpecs : SpecsBase // System.Environment when they are not provided explicitly to CliApplication. // Arrange - var command = Cli.Wrap("dotnet") - .WithArguments(a => a - .Add(Dummy.Program.Location) - .Add("env-test") - ) + var command = Cli.Wrap(Dummy.Program.FilePath) + .WithArguments("env-test") .WithEnvironmentVariables(e => e .Set("ENV_TARGET", "Mars") );