From c81bc5fe1d503fc7734fae4b02a72a64f7aa0fe9 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:53:06 +0100 Subject: [PATCH] Fix tests with incorrect validation that were in the main branch Tests had incorrect expectations for the parsing of branch + default command arguments --- .../Unit/CommandAppTests.Branches.cs | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Branches.cs b/src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Branches.cs index fc54784..9f51d80 100644 --- a/src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Branches.cs +++ b/src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Branches.cs @@ -62,10 +62,8 @@ public sealed partial class CommandAppTests }); } - [SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1515:SingleLineCommentMustBePrecededByBlankLine", Justification = "Helps to illustrate the expected behaviour of this unit test.")] - [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1005:SingleLineCommentsMustBeginWithSingleSpace", Justification = "Helps to illustrate the expected behaviour of this unit test.")] [Fact] - public void Should_Be_Unable_To_Parse_Default_Command_Arguments_Relaxed_Parsing() + public void Should_Parse_Branch_And_Default_Command_Arguments_Relaxed_Parsing() { // Given var app = new CommandAppTester(); @@ -81,25 +79,27 @@ public sealed partial class CommandAppTests // When var result = app.Run(new[] { - // The CommandTreeParser should be unable to determine which command line - // arguments belong to the branch and which belong to the branch's - // default command (once inserted). - "animal", "4", "--name", "Kitty", + // The CommandTreeParser should determine which command line arguments + // belong to the branch and which belong to the branch's default command. + "animal", "4", "-a", "false", "--name", "Kitty", "--agility", "four", "--nick-name", "Felix" }); // Then result.ExitCode.ShouldBe(0); result.Settings.ShouldBeOfType().And(cat => { + cat.IsAlive.ShouldBeFalse(); cat.Legs.ShouldBe(4); - //cat.Name.ShouldBe("Kitty"); //<-- Should normally be correct, but instead name will be added to the remaining arguments (see below). + cat.Name.ShouldBe("Kitty"); + cat.Agility.ShouldBe(4); }); result.Context.Remaining.Parsed.Count.ShouldBe(1); - result.Context.ShouldHaveRemainingArgument("--name", values: new[] { "Kitty", }); + result.Context.ShouldHaveRemainingArgument("--nick-name", values: new[] { "Felix" }); + result.Context.Remaining.Raw.Count.ShouldBe(0); } [Fact] - public void Should_Be_Unable_To_Parse_Default_Command_Arguments_Strict_Parsing() + public void Should_Parse_Branch_And_Default_Command_Arguments_Strict_Parsing() { // Given var app = new CommandAppTester(); @@ -114,22 +114,25 @@ public sealed partial class CommandAppTests }); // When - var result = Record.Exception(() => + var result = app.Run(new[] { - app.Run(new[] - { - // The CommandTreeParser should be unable to determine which command line - // arguments belong to the branch and which belong to the branch's - // default command (once inserted). - "animal", "4", "--name", "Kitty", - }); + // The CommandTreeParser should determine which command line arguments + // belong to the branch and which belong to the branch's default command. + "animal", "4", "-a", "false", "--name", "Kitty", "--agility", "four", "--", "--nick-name", "Felix" }); // Then - result.ShouldBeOfType().And(ex => + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(cat => { - ex.Message.ShouldBe("Unknown option 'name'."); + cat.IsAlive.ShouldBeFalse(); + cat.Legs.ShouldBe(4); + cat.Name.ShouldBe("Kitty"); + cat.Agility.ShouldBe(4); }); + result.Context.Remaining.Parsed.Count.ShouldBe(1); + result.Context.ShouldHaveRemainingArgument("--nick-name", values: new[] { "Felix" }); + result.Context.Remaining.Raw.Count.ShouldBe(2); } [Theory]