diff --git a/.gitignore b/.gitignore index a438902..69a2791 100644 --- a/.gitignore +++ b/.gitignore @@ -399,3 +399,5 @@ FodyWeavers.xsd # Verify snapshots *.received.* + +launchSettings.json diff --git a/CHANGELOG.md b/CHANGELOG.md index eb5a107..cbf0f84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +### Added + - Build and test on each platform version available - macOS 13 - macOS 14 @@ -15,6 +17,11 @@ - Ubuntu 24.04 - Windows 11 +### Updated + +- Bumped `System.CommandLine` from 2.0.0-beta4.22272.1 to 2.0.0-beta5.25306.1 +- Bumped `System.CommandLine.Rendering` from 0.4.0-alpha.22272.1 to 0.4.0-alpha.25306.1 + ## [0.6.0](https://github.com/xt0rted/dotnet-run-script/compare/v0.5.0...v0.6.0) - 2024-04-10 - Dropped support for .NET Core 3.1 diff --git a/src/ConsoleWriter.cs b/src/ConsoleWriter.cs index 5a5c65f..2312c2c 100644 --- a/src/ConsoleWriter.cs +++ b/src/ConsoleWriter.cs @@ -1,19 +1,22 @@ namespace RunScript; +using System; using System.CommandLine.Rendering; using System.Globalization; internal class ConsoleWriter : IConsoleWriter { - private readonly IConsole _console; - private readonly IFormatProvider? _consoleFormatProvider; - + private readonly TextWriter _output; + private readonly IFormatProvider _consoleFormatProvider; private readonly bool _verbose; - public ConsoleWriter(IConsole console, IFormatProvider consoleFormatProvider, bool verbose) + public ConsoleWriter(TextWriter output, IFormatProvider consoleFormatProvider, bool verbose) { - _console = console ?? throw new ArgumentNullException(nameof(console)); - _consoleFormatProvider = consoleFormatProvider ?? throw new ArgumentNullException(nameof(consoleFormatProvider)); + ArgumentNullException.ThrowIfNull(output); + ArgumentNullException.ThrowIfNull(consoleFormatProvider); + + _output = output; + _consoleFormatProvider = consoleFormatProvider; _verbose = verbose; } @@ -23,36 +26,36 @@ private void WriteLine(AnsiControlCode modifierOn, AnsiControlCode modifierOff, { if (message is not null) { - _console.Out.Write(modifierOn.ToString(null, _consoleFormatProvider)); + _output.Write(modifierOn.ToString(null, _consoleFormatProvider)); if (args?.Length > 0) { - _console.Out.Write(string.Format(CultureInfo.CurrentCulture, message, args)); + _output.Write(string.Format(CultureInfo.CurrentCulture, message, args)); } else { - _console.Out.Write(message); + _output.Write(message); } - _console.Out.Write(modifierOff.ToString(null, _consoleFormatProvider)); - _console.Out.Write(Environment.NewLine); + _output.Write(modifierOff.ToString(null, _consoleFormatProvider)); + _output.Write(Environment.NewLine); } } public void Raw(string? message) - => _console.Out.Write(message); + => _output.Write(message); public void VerboseBanner() => LineVerbose("Verbose mode is on. This will print more information."); public void BlankLine() - => _console.Out.Write(Environment.NewLine); + => _output.Write(Environment.NewLine); public void BlankLineVerbose() { if (_verbose) { - _console.Out.Write(Environment.NewLine); + _output.Write(Environment.NewLine); } } diff --git a/src/GlobalArguments.cs b/src/GlobalArguments.cs index 8cf65dc..bfa9356 100644 --- a/src/GlobalArguments.cs +++ b/src/GlobalArguments.cs @@ -2,8 +2,10 @@ namespace RunScript; public static class GlobalArguments { - public static readonly Argument Scripts = new("scripts", "One or more scripts to run") + public static readonly Argument Scripts = new("scripts") { Arity = ArgumentArity.ZeroOrMore, + Description = "One or more scripts to run", + DefaultValueFactory = _ => [], }; } diff --git a/src/GlobalOptions.cs b/src/GlobalOptions.cs index c3f85b0..fa1df6d 100644 --- a/src/GlobalOptions.cs +++ b/src/GlobalOptions.cs @@ -2,12 +2,19 @@ namespace RunScript; public static class GlobalOptions { - public static readonly Option IfPresent = new("--if-present", "Don't exit with an error code if the script isn't found"); + public static readonly Option IfPresent = new("--if-present") + { + Description = "Don't exit with an error code if the script isn't found", + }; - public static readonly Option ScriptShell = new("--script-shell", "The shell to use when running scripts (cmd, pwsh, sh, etc.)") + public static readonly Option ScriptShell = new("--script-shell") { - ArgumentHelpName = "shell", + Description = "The shell to use when running scripts (cmd, pwsh, sh, etc.)", + HelpName = "shell", }; - public static readonly Option Verbose = new(new[] { "-v", "--verbose" }, "Enable verbose output"); + public static readonly Option Verbose = new("--verbose", "-v") + { + Description = "Enable verbose output", + }; } diff --git a/src/Program.cs b/src/Program.cs index 8ff6f85..4bff194 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -1,6 +1,3 @@ -using System.CommandLine.Builder; -using System.CommandLine.Parsing; - using RunScript; var environment = new EnvironmentWrapper(); @@ -8,34 +5,12 @@ var rootCommand = new RunScriptCommand( environment, consoleFormatProvider, - environment.CurrentDirectory); - -var parser = new CommandLineBuilder(rootCommand) - .UseVersionOption() - .UseHelp() - .UseEnvironmentVariableDirective() - .UseParseDirective() - .UseSuggestDirective() - .RegisterWithDotnetSuggest() - .UseParseErrorReporting() - .UseExceptionHandler((ex, ctx) => - { - var verbose = ctx.ParseResult.HasOption(GlobalOptions.Verbose); - var writer = new ConsoleWriter(ctx.Console, consoleFormatProvider, verbose); - - if (verbose) - { - writer.Error(ex.ToString()); - } - else - { - writer.Error(ex.Message); - } - }) - .CancelOnProcessTermination() - .EnableLegacyDoubleDashBehavior() - .Build(); + environment.CurrentDirectory) +{ + new DiagramDirective(), + new EnvironmentVariablesDirective() +}; -var parseResult = parser.Parse(args); +var parseResult = rootCommand.Parse(args); return await parseResult.InvokeAsync(); diff --git a/src/RunScriptCommand.cs b/src/RunScriptCommand.cs index 9951ec9..98940e0 100644 --- a/src/RunScriptCommand.cs +++ b/src/RunScriptCommand.cs @@ -1,12 +1,10 @@ namespace RunScript; -using System.CommandLine.Invocation; - using DotNet.Globbing; using RunScript.Logging; -internal class RunScriptCommand : RootCommand, ICommandHandler +internal class RunScriptCommand : RootCommand { private readonly IEnvironment _environment; private readonly IFormatProvider _consoleFormatProvider; @@ -25,28 +23,25 @@ internal RunScriptCommand( _workingDirectory = workingDirectory; - AddArgument(GlobalArguments.Scripts); + Arguments.Add(GlobalArguments.Scripts); - AddOption(GlobalOptions.IfPresent); - AddOption(GlobalOptions.ScriptShell); - AddOption(GlobalOptions.Verbose); + Options.Add(GlobalOptions.IfPresent); + Options.Add(GlobalOptions.ScriptShell); + Options.Add(GlobalOptions.Verbose); - Handler = this; + SetAction(InvokeAsync); } - public int Invoke(InvocationContext context) - => throw new NotImplementedException(); - - public async Task InvokeAsync(InvocationContext context) + internal async Task InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken) { - ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(parseResult); - var ifPresent = context.ParseResult.GetValueForOption(GlobalOptions.IfPresent); - var scriptShell = context.ParseResult.GetValueForOption(GlobalOptions.ScriptShell); - var verbose = context.ParseResult.GetValueForOption(GlobalOptions.Verbose); - var scripts = context.ParseResult.GetValueForArgument(GlobalArguments.Scripts); + var ifPresent = parseResult.GetValue(GlobalOptions.IfPresent); + var scriptShell = parseResult.GetValue(GlobalOptions.ScriptShell); + var verbose = parseResult.GetValue(GlobalOptions.Verbose); + var scripts = parseResult.GetRequiredValue(GlobalArguments.Scripts); - var writer = new ConsoleWriter(context.Console, _consoleFormatProvider, verbose); + var writer = new ConsoleWriter(parseResult.Configuration.Output, _consoleFormatProvider, verbose); writer.VerboseBanner(); @@ -113,9 +108,9 @@ public async Task InvokeAsync(InvocationContext context) // UnparsedTokens is backed by string[] so if we cast // back to that we get a lot better perf down the line. // Hopefully this doesn't break in the future 🤞 - var scriptArgs = (string[])context.ParseResult.UnparsedTokens; + var scriptArgs = (string[])parseResult.UnmatchedTokens; - var scriptRunner = builder.CreateGroupRunner(context.GetCancellationToken()); + var scriptRunner = builder.CreateGroupRunner(cancellationToken); var result = await scriptRunner.RunAsync( script.Name, diff --git a/src/run-script.csproj b/src/run-script.csproj index 3b4bac2..6c43d46 100644 --- a/src/run-script.csproj +++ b/src/run-script.csproj @@ -47,8 +47,8 @@ - - + + diff --git a/test/CommandBuilderTests.cs b/test/CommandBuilderTests.cs index 8122251..6c5ae64 100644 --- a/test/CommandBuilderTests.cs +++ b/test/CommandBuilderTests.cs @@ -1,7 +1,6 @@ namespace RunScript; using System.Collections.Generic; -using System.CommandLine.IO; using System.CommandLine.Rendering; [Trait("category", "unit")] @@ -91,12 +90,12 @@ public void CreateGroupRunner_should_create_a_runner(bool isWindows) private static CommandBuilder SetUpTest(bool isWindows, string? comSpec = DefaultComSpec) { - var console = new TestConsole(); + var output = new StringWriter(); var consoleFormatProvider = new ConsoleFormatInfo { SupportsAnsiCodes = false, }; - var consoleWriter = new ConsoleWriter(console, consoleFormatProvider, verbose: true); + var consoleWriter = new ConsoleWriter(output, consoleFormatProvider, verbose: true); var project = new Project { diff --git a/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_and_pre_and_post_scripts_when_env_script_not_defined_isWindows=False.verified.txt b/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_and_pre_and_post_scripts_when_env_script_not_defined_isWindows=False.verified.txt index 5b8c70d..22e55b3 100644 --- a/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_and_pre_and_post_scripts_when_env_script_not_defined_isWindows=False.verified.txt +++ b/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_and_pre_and_post_scripts_when_env_script_not_defined_isWindows=False.verified.txt @@ -1,16 +1,11 @@ { - console: { - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: + output: > env value1=value 1 value2=value 2 value3=value 3 - - }, +, commandRunners: [ { Name: preenv, diff --git a/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_and_pre_and_post_scripts_when_env_script_not_defined_isWindows=True.verified.txt b/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_and_pre_and_post_scripts_when_env_script_not_defined_isWindows=True.verified.txt index 5b8c70d..22e55b3 100644 --- a/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_and_pre_and_post_scripts_when_env_script_not_defined_isWindows=True.verified.txt +++ b/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_and_pre_and_post_scripts_when_env_script_not_defined_isWindows=True.verified.txt @@ -1,16 +1,11 @@ { - console: { - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: + output: > env value1=value 1 value2=value 2 value3=value 3 - - }, +, commandRunners: [ { Name: preenv, diff --git a/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_when_env_script_not_defined_isWindows=False.verified.txt b/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_when_env_script_not_defined_isWindows=False.verified.txt index aecdd99..4a5549c 100644 --- a/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_when_env_script_not_defined_isWindows=False.verified.txt +++ b/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_when_env_script_not_defined_isWindows=False.verified.txt @@ -1,12 +1,6 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: + > env value1=value 1 value2=value 2 value3=value 3 - -} \ No newline at end of file diff --git a/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_when_env_script_not_defined_isWindows=True.verified.txt b/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_when_env_script_not_defined_isWindows=True.verified.txt index aecdd99..4a5549c 100644 --- a/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_when_env_script_not_defined_isWindows=True.verified.txt +++ b/test/CommandGroupRunnerTests.Should_emit_environment_variable_list_when_env_script_not_defined_isWindows=True.verified.txt @@ -1,12 +1,6 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: + > env value1=value 1 value2=value 2 value3=value 3 - -} \ No newline at end of file diff --git a/test/CommandGroupRunnerTests.Should_run_env_script_if_defined_isWindows=False.verified.txt b/test/CommandGroupRunnerTests.Should_run_env_script_if_defined_isWindows=False.verified.txt index 1e37322..d5d681b 100644 --- a/test/CommandGroupRunnerTests.Should_run_env_script_if_defined_isWindows=False.verified.txt +++ b/test/CommandGroupRunnerTests.Should_run_env_script_if_defined_isWindows=False.verified.txt @@ -1,9 +1,5 @@ { - console: { - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false - }, + output: , commandRunners: [ { Name: env, diff --git a/test/CommandGroupRunnerTests.Should_run_env_script_if_defined_isWindows=True.verified.txt b/test/CommandGroupRunnerTests.Should_run_env_script_if_defined_isWindows=True.verified.txt index 1e37322..d5d681b 100644 --- a/test/CommandGroupRunnerTests.Should_run_env_script_if_defined_isWindows=True.verified.txt +++ b/test/CommandGroupRunnerTests.Should_run_env_script_if_defined_isWindows=True.verified.txt @@ -1,9 +1,5 @@ { - console: { - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false - }, + output: , commandRunners: [ { Name: env, diff --git a/test/CommandGroupRunnerTests.cs b/test/CommandGroupRunnerTests.cs index 5f55182..00bb3e4 100644 --- a/test/CommandGroupRunnerTests.cs +++ b/test/CommandGroupRunnerTests.cs @@ -1,7 +1,6 @@ namespace RunScript; using System.Collections.Generic; -using System.CommandLine.IO; using System.CommandLine.Rendering; using System.Threading.Tasks; @@ -123,7 +122,7 @@ public async Task Should_emit_environment_variable_list_when_env_script_not_defi new(999), }; - var (console, groupRunner) = SetUpTest(commandRunners, isWindows); + var (output, groupRunner) = SetUpTest(commandRunners, isWindows); // When var result = await groupRunner.RunAsync("env", null); @@ -133,7 +132,7 @@ public async Task Should_emit_environment_variable_list_when_env_script_not_defi A.CallTo(() => groupRunner.BuildCommand()).MustNotHaveHappened(); - await Verify(console).UseParameters(isWindows); + await Verify(output).UseParameters(isWindows); } [Theory] @@ -149,7 +148,7 @@ public async Task Should_emit_environment_variable_list_and_pre_and_post_scripts new(999), }; - var (console, groupRunner) = SetUpTest( + var (output, groupRunner) = SetUpTest( commandRunners, isWindows, scripts => @@ -169,7 +168,7 @@ public async Task Should_emit_environment_variable_list_and_pre_and_post_scripts await Verify( new { - console, + output, commandRunners, }) .UseParameters(isWindows); @@ -187,7 +186,7 @@ public async Task Should_run_env_script_if_defined(bool isWindows) new(999), }; - var (console, groupRunner) = SetUpTest( + var (output, groupRunner) = SetUpTest( commandRunners, isWindows, scripts => scripts.Add("env", "echo env")); @@ -203,7 +202,7 @@ public async Task Should_run_env_script_if_defined(bool isWindows) await Verify( new { - console, + output, commandRunners, }) .UseParameters(isWindows); @@ -236,17 +235,17 @@ public async Task Should_return_first_error_hit(bool isWindows) await Verify(commandRunners).UseParameters(isWindows); } - private static (TestConsole console, CommandGroupRunner groupRunner) SetUpTest( + private static (StringWriter output, CommandGroupRunner groupRunner) SetUpTest( TestCommandRunner[] commandRunners, bool isWindows, Action>? scriptSetup = null) { - var console = new TestConsole(); + var output = new StringWriter(); var consoleFormatProvider = new ConsoleFormatInfo { SupportsAnsiCodes = false, }; - var consoleWriter = new ConsoleWriter(console, consoleFormatProvider, verbose: true); + var consoleWriter = new ConsoleWriter(output, consoleFormatProvider, verbose: true); var scripts = new Dictionary(StringComparer.OrdinalIgnoreCase) { @@ -294,7 +293,7 @@ private static (TestConsole console, CommandGroupRunner groupRunner) SetUpTest( A.CallTo(() => groupRunner.BuildCommand()).ReturnsNextFromSequence(commandRunners); - return (console, groupRunner); + return (output, groupRunner); } private class TestCommandRunner : ICommandRunner diff --git a/test/GlobalCommandsTests.Should_log_all_available_environment_variables.verified.txt b/test/GlobalCommandsTests.Should_log_all_available_environment_variables.verified.txt index 63deeed..5fccc28 100644 --- a/test/GlobalCommandsTests.Should_log_all_available_environment_variables.verified.txt +++ b/test/GlobalCommandsTests.Should_log_all_available_environment_variables.verified.txt @@ -1,13 +1,7 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: + > env value1=value 1 value2=value 2 value3=value 3 value4=value 4 - -} \ No newline at end of file diff --git a/test/GlobalCommandsTests.Should_log_all_available_scripts.verified.txt b/test/GlobalCommandsTests.Should_log_all_available_scripts.verified.txt index b0bbbb4..ad51521 100644 --- a/test/GlobalCommandsTests.Should_log_all_available_scripts.verified.txt +++ b/test/GlobalCommandsTests.Should_log_all_available_scripts.verified.txt @@ -1,9 +1,4 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -Available via `dotnet r`: +Available via `dotnet r`: clean echo clean @@ -29,5 +24,3 @@ Available via `dotnet r`: postpack echo pack - -} \ No newline at end of file diff --git a/test/GlobalCommandsTests.cs b/test/GlobalCommandsTests.cs index c659ec1..bc6b740 100644 --- a/test/GlobalCommandsTests.cs +++ b/test/GlobalCommandsTests.cs @@ -1,7 +1,6 @@ namespace RunScript; using System.Collections.Generic; -using System.CommandLine.IO; using System.CommandLine.Rendering; using System.Threading.Tasks; @@ -12,12 +11,12 @@ public class GlobalCommandsTests public async Task Should_log_all_available_scripts() { // Given - var console = new TestConsole(); + var output = new StringWriter(); var consoleFormatProvider = new ConsoleFormatInfo { SupportsAnsiCodes = false, }; - var consoleWriter = new ConsoleWriter(console, consoleFormatProvider, verbose: true); + var consoleWriter = new ConsoleWriter(output, consoleFormatProvider, verbose: true); var scripts = new Dictionary(StringComparer.OrdinalIgnoreCase) { @@ -35,19 +34,19 @@ public async Task Should_log_all_available_scripts() GlobalCommands.PrintAvailableScripts(consoleWriter, scripts); // Then - await Verify(console); + await Verify(output); } [Fact] public async Task Should_log_all_available_environment_variables() { // Given - var console = new TestConsole(); + var output = new StringWriter(); var consoleFormatProvider = new ConsoleFormatInfo { SupportsAnsiCodes = false, }; - var consoleWriter = new ConsoleWriter(console, consoleFormatProvider, verbose: true); + var consoleWriter = new ConsoleWriter(output, consoleFormatProvider, verbose: true); var environment = new TestEnvironment("/test/path", isWindows: true); @@ -61,6 +60,6 @@ public async Task Should_log_all_available_environment_variables() GlobalCommands.PrintEnvironmentVariables(consoleWriter, environment); // Then - await Verify(console); + await Verify(output); } } diff --git a/test/Integration/CommandBuilderTests.UnixPlatforms.Should_execute_single_script_in_shell_shellOverride=default.verified.txt b/test/Integration/CommandBuilderTests.UnixPlatforms.Should_execute_single_script_in_shell_shellOverride=default.verified.txt index 5b1218d..bf31892 100644 --- a/test/Integration/CommandBuilderTests.UnixPlatforms.Should_execute_single_script_in_shell_shellOverride=default.verified.txt +++ b/test/Integration/CommandBuilderTests.UnixPlatforms.Should_execute_single_script_in_shell_shellOverride=default.verified.txt @@ -1,13 +1,7 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -> Using shell: sh +> Using shell: sh > test > echo testing testing -} \ No newline at end of file diff --git a/test/Integration/CommandBuilderTests.UnixPlatforms.Should_execute_single_script_in_shell_shellOverride=pwsh.verified.txt b/test/Integration/CommandBuilderTests.UnixPlatforms.Should_execute_single_script_in_shell_shellOverride=pwsh.verified.txt index 61f3a14..5e7bb95 100644 --- a/test/Integration/CommandBuilderTests.UnixPlatforms.Should_execute_single_script_in_shell_shellOverride=pwsh.verified.txt +++ b/test/Integration/CommandBuilderTests.UnixPlatforms.Should_execute_single_script_in_shell_shellOverride=pwsh.verified.txt @@ -1,13 +1,7 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -> Using shell: pwsh +> Using shell: pwsh > test > echo testing testing -} \ No newline at end of file diff --git a/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=bash.verified.txt b/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=bash.verified.txt index ca9c7a6..d93c37c 100644 --- a/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=bash.verified.txt +++ b/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=bash.verified.txt @@ -1,13 +1,7 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -> Using shell: C:\Program Files\Git\bin\bash.exe +> Using shell: C:\Program Files\Git\bin\bash.exe > test > echo testing testing -} \ No newline at end of file diff --git a/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=cmd.exe.verified.txt b/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=cmd.exe.verified.txt index 280f62c..1fd2163 100644 --- a/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=cmd.exe.verified.txt +++ b/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=cmd.exe.verified.txt @@ -1,13 +1,7 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -> Using shell: cmd.exe +> Using shell: cmd.exe > test > echo testing testing -} \ No newline at end of file diff --git a/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=default.verified.txt b/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=default.verified.txt index 467994f..87f2725 100644 --- a/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=default.verified.txt +++ b/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=default.verified.txt @@ -1,13 +1,7 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -> Using shell: cmd +> Using shell: cmd > test > echo testing testing -} \ No newline at end of file diff --git a/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=pwsh.verified.txt b/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=pwsh.verified.txt index 61f3a14..5e7bb95 100644 --- a/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=pwsh.verified.txt +++ b/test/Integration/CommandBuilderTests.WindowsPlatform.Should_execute_single_script_in_shell_shellOverride=pwsh.verified.txt @@ -1,13 +1,7 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -> Using shell: pwsh +> Using shell: pwsh > test > echo testing testing -} \ No newline at end of file diff --git a/test/Integration/CommandBuilderTests.cs b/test/Integration/CommandBuilderTests.cs index 776800e..e267ad1 100644 --- a/test/Integration/CommandBuilderTests.cs +++ b/test/Integration/CommandBuilderTests.cs @@ -2,7 +2,6 @@ namespace RunScript.Integration; using System; using System.Collections.Generic; -using System.CommandLine.IO; using System.CommandLine.Rendering; public static class CommandBuilderTests @@ -40,12 +39,12 @@ await CommandBuilderTests.Should_execute_single_script_in_shell( private static async Task Should_execute_single_script_in_shell(bool isWindows, string? shellOverride) { - var console = new TestConsole(); + var output = new StringWriter(); var consoleFormatProvider = new ConsoleFormatInfo { SupportsAnsiCodes = false, }; - var consoleWriter = new ConsoleWriter(console, consoleFormatProvider, verbose: true); + var consoleWriter = new ConsoleWriter(output, consoleFormatProvider, verbose: true); var environment = new TestEnvironment(isWindows: isWindows); @@ -75,7 +74,7 @@ private static async Task Should_execute_single_script_in_shell(bool isWindows, name: "test", scriptArgs: null); - await Verify(console).UseParameters(ShellName(shellOverride)); + await Verify(output).UseParameters(ShellName(shellOverride)); result.ShouldBe(0); } diff --git a/test/Logging/GitHubActionsLogGroupTests.Should_escape_group_name.verified.txt b/test/Logging/GitHubActionsLogGroupTests.Should_escape_group_name.verified.txt index 359136f..a06326f 100644 --- a/test/Logging/GitHubActionsLogGroupTests.Should_escape_group_name.verified.txt +++ b/test/Logging/GitHubActionsLogGroupTests.Should_escape_group_name.verified.txt @@ -1,9 +1,4 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -::group::dotnet r plain +::group::dotnet r plain ::endgroup:: ::group::dotnet r percent: %2525 ::endgroup:: @@ -13,5 +8,3 @@ ::endgroup:: ::group::dotnet r everything: %25%0D%0A ::endgroup:: - -} \ No newline at end of file diff --git a/test/Logging/GitHubActionsLogGroupTests.cs b/test/Logging/GitHubActionsLogGroupTests.cs index 0926236..d63388c 100644 --- a/test/Logging/GitHubActionsLogGroupTests.cs +++ b/test/Logging/GitHubActionsLogGroupTests.cs @@ -1,6 +1,5 @@ namespace RunScript.Logging; -using System.CommandLine.IO; using System.CommandLine.Rendering; [Trait("category", "unit")] @@ -10,12 +9,12 @@ public class GitHubActionsLogGroupTests public async Task Should_escape_group_name() { // Given - var console = new TestConsole(); + var output = new StringWriter(); var consoleFormatProvider = new ConsoleFormatInfo { SupportsAnsiCodes = false, }; - var consoleWriter = new ConsoleWriter(console, consoleFormatProvider, verbose: false); + var consoleWriter = new ConsoleWriter(output, consoleFormatProvider, verbose: false); // When createGroup("plain"); @@ -25,7 +24,7 @@ public async Task Should_escape_group_name() createGroup("everything: %\r\n"); // Then - await Verify(console); + await Verify(output); void createGroup(string groupName) { diff --git a/test/RunScriptCommandTests.RunResults.Should_handle_any_error_result_exitCode=1.verified.txt b/test/RunScriptCommandTests.RunResults.Should_handle_any_error_result_exitCode=1.verified.txt index 7e7edd0..d84ef26 100644 --- a/test/RunScriptCommandTests.RunResults.Should_handle_any_error_result_exitCode=1.verified.txt +++ b/test/RunScriptCommandTests.RunResults.Should_handle_any_error_result_exitCode=1.verified.txt @@ -1,8 +1 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -ERROR: "test" exited with 1 - -} \ No newline at end of file +ERROR: "test" exited with 1 diff --git a/test/RunScriptCommandTests.RunResults.Should_handle_any_error_result_exitCode=13.verified.txt b/test/RunScriptCommandTests.RunResults.Should_handle_any_error_result_exitCode=13.verified.txt index e97db1a..0400790 100644 --- a/test/RunScriptCommandTests.RunResults.Should_handle_any_error_result_exitCode=13.verified.txt +++ b/test/RunScriptCommandTests.RunResults.Should_handle_any_error_result_exitCode=13.verified.txt @@ -1,8 +1 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -ERROR: "test" exited with 13 - -} \ No newline at end of file +ERROR: "test" exited with 13 diff --git a/test/RunScriptCommandTests.RunResults.Should_handle_multiple_error_results.verified.txt b/test/RunScriptCommandTests.RunResults.Should_handle_multiple_error_results.verified.txt index b454046..8f1777f 100644 --- a/test/RunScriptCommandTests.RunResults.Should_handle_multiple_error_results.verified.txt +++ b/test/RunScriptCommandTests.RunResults.Should_handle_multiple_error_results.verified.txt @@ -1,9 +1,2 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false, - Out: -ERROR: "build" exited with 13 +ERROR: "build" exited with 13 ERROR: "test" exited with 99 - -} \ No newline at end of file diff --git a/test/RunScriptCommandTests.RunResults.Should_handle_multiple_success_results.verified.txt b/test/RunScriptCommandTests.RunResults.Should_handle_multiple_success_results.verified.txt index 839ee60..c1b8d74 100644 --- a/test/RunScriptCommandTests.RunResults.Should_handle_multiple_success_results.verified.txt +++ b/test/RunScriptCommandTests.RunResults.Should_handle_multiple_success_results.verified.txt @@ -1,5 +1 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false -} \ No newline at end of file +emptyString \ No newline at end of file diff --git a/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=0.verified.txt b/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=0.verified.txt index 839ee60..c1b8d74 100644 --- a/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=0.verified.txt +++ b/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=0.verified.txt @@ -1,5 +1 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false -} \ No newline at end of file +emptyString \ No newline at end of file diff --git a/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=1.verified.txt b/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=1.verified.txt index 839ee60..c1b8d74 100644 --- a/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=1.verified.txt +++ b/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=1.verified.txt @@ -1,5 +1 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false -} \ No newline at end of file +emptyString \ No newline at end of file diff --git a/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=13.verified.txt b/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=13.verified.txt index 839ee60..c1b8d74 100644 --- a/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=13.verified.txt +++ b/test/RunScriptCommandTests.RunResults.Should_handle_single_result_exitCode=13.verified.txt @@ -1,5 +1 @@ -{ - IsErrorRedirected: false, - IsInputRedirected: false, - IsOutputRedirected: false -} \ No newline at end of file +emptyString \ No newline at end of file diff --git a/test/RunScriptCommandTests.cs b/test/RunScriptCommandTests.cs index e155f46..685e274 100644 --- a/test/RunScriptCommandTests.cs +++ b/test/RunScriptCommandTests.cs @@ -1,7 +1,6 @@ namespace RunScript; using System.Collections.Generic; -using System.CommandLine.IO; using System.CommandLine.Rendering; public static class RunScriptCommandTests @@ -174,7 +173,7 @@ public class RunResults public async Task Should_handle_single_result(int exitCode) { // Given - var (console, writer) = SetUpTest(); + var (output, writer) = SetUpTest(); var results = new List { new("build", exitCode), @@ -188,14 +187,14 @@ public async Task Should_handle_single_result(int exitCode) // Then result.ShouldBe(exitCode); - await Verify(console).UseParameters(exitCode); + await Verify(output).UseParameters(exitCode); } [Fact] public async Task Should_handle_multiple_success_results() { // Given - var (console, writer) = SetUpTest(); + var (output, writer) = SetUpTest(); var results = new List { new("build", 0), @@ -210,14 +209,14 @@ public async Task Should_handle_multiple_success_results() // Then result.ShouldBe(0); - await Verify(console); + await Verify(output); } [Fact] public async Task Should_handle_multiple_error_results() { // Given - var (console, writer) = SetUpTest(); + var (output, writer) = SetUpTest(); var results = new List { new("build", 13), @@ -232,7 +231,7 @@ public async Task Should_handle_multiple_error_results() // Then result.ShouldBe(1); - await Verify(console); + await Verify(output); } [Theory] @@ -241,7 +240,7 @@ public async Task Should_handle_multiple_error_results() public async Task Should_handle_any_error_result(int exitCode) { // Given - var (console, writer) = SetUpTest(); + var (output, writer) = SetUpTest(); var results = new List { new("build", 0), @@ -256,21 +255,21 @@ public async Task Should_handle_any_error_result(int exitCode) // Then result.ShouldBe(1); - await Verify(console).UseParameters(exitCode); + await Verify(output).UseParameters(exitCode); } - private static (TestConsole console, IConsoleWriter writer) SetUpTest() + private static (StringWriter output, IConsoleWriter writer) SetUpTest() { - var console = new TestConsole(); + var output = new StringWriter(); var consoleWriter = new ConsoleWriter( - console, + output, new ConsoleFormatInfo { SupportsAnsiCodes = false, }, verbose: true); - return (console, consoleWriter); + return (output, consoleWriter); } } }