From c4a97f3c89d63cf22e564a79c968d635ee903350 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:45:09 +0100 Subject: [PATCH] Improved unit test coverage using Spectre.Console.Tests.Data.VersionCommand --- .../Unit/CommandAppTests.Version.Help.cs | 96 +++++++++---------- 1 file changed, 45 insertions(+), 51 deletions(-) diff --git a/src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Version.Help.cs b/src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Version.Help.cs index ddf7b38..b2cdec0 100644 --- a/src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Version.Help.cs +++ b/src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Version.Help.cs @@ -34,10 +34,6 @@ public sealed partial class CommandAppTests { // Given var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.AddCommand("empty"); - }); // When var result = fixture.Run(helpOption); @@ -46,27 +42,6 @@ public sealed partial class CommandAppTests result.Output.ShouldNotContain("-v, --version Prints version information"); } - [Theory] - [InlineData("-?")] - [InlineData("-h")] - [InlineData("--help")] - public void Help_Should_Not_Include_Application_Version_Flag_For_Command(string helpOption) - { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationVersion("1.0"); - configurator.AddCommand("empty"); - }); - - // When - var result = fixture.Run("empty", helpOption); - - // Then - result.Output.ShouldNotContain("-v, --version Prints version information"); - } - [Theory] [InlineData("-?")] [InlineData("-h")] @@ -88,6 +63,27 @@ public sealed partial class CommandAppTests result.Output.ShouldContain("-v, --version Prints version information"); } + [Theory] + [InlineData("-?")] + [InlineData("-h")] + [InlineData("--help")] + public void Help_Should_Not_Include_Application_Version_Flag_For_Command(string helpOption) + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => + { + configurator.SetApplicationVersion("1.0"); + configurator.AddCommand("empty"); + }); + + // When + var result = fixture.Run("empty", helpOption); + + // Then + result.Output.ShouldNotContain("-v, --version Prints version information"); + } + [Theory] [InlineData("-?")] [InlineData("-h")] @@ -125,39 +121,17 @@ public sealed partial class CommandAppTests configurator.SetApplicationVersion("1.0"); configurator.AddBranch("branch", branch => { - branch.AddCommand("hello"); + branch.AddCommand("empty"); }); }); // When - var result = fixture.Run("branch", "hello", helpOption); + var result = fixture.Run("branch", "empty", helpOption); // Then result.Output.ShouldNotContain("-v, --version Prints version information"); } - [Theory] - [InlineData("-?")] - [InlineData("-h")] - [InlineData("--help")] - public void Help_Should_Include_Command_Version_Flag_For_Command(string helpOption) - { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationVersion("1.0"); - configurator.AddCommand("empty"); - }); - - // When - var result = fixture.Run("empty", helpOption); - - // Then - result.Output.ShouldContain("-v, --version The command version"); - result.Output.ShouldNotContain("-v, --version Prints version information"); - } - /// /// When a command with a version flag in the settings is set as the application default command, /// then override the in-built Application Version flag with the command version flag instead. @@ -186,6 +160,28 @@ public sealed partial class CommandAppTests result.Output.ShouldNotContain("-v, --version Prints version information"); } + [Theory] + [InlineData("-?")] + [InlineData("-h")] + [InlineData("--help")] + public void Help_Should_Include_Command_Version_Flag_For_Command(string helpOption) + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => + { + configurator.SetApplicationVersion("1.0"); + configurator.AddCommand("hello"); + }); + + // When + var result = fixture.Run("hello", helpOption); + + // Then + result.Output.ShouldContain("-v, --version The command version"); + result.Output.ShouldNotContain("-v, --version Prints version information"); + } + [Theory] [InlineData("-?")] [InlineData("-h")] @@ -235,8 +231,6 @@ public sealed partial class CommandAppTests result.Output.ShouldContain("-v, --version The command version"); result.Output.ShouldNotContain("-v, --version Prints version information"); } - - } } } \ No newline at end of file