diff --git a/test/CommandLineTests.Help.cs b/test/CommandLineTests.Help.cs index efb63cc..716260a 100644 --- a/test/CommandLineTests.Help.cs +++ b/test/CommandLineTests.Help.cs @@ -681,5 +681,84 @@ public void HelpWhenPassMoreParametersThanExpected() ); } + [Fact] + public void EnsureThatRightParameterIsReportedForGroups() + { + // Invalid option should be in exception text + var commandLine = "Command1 req1 -opt1=value"; + + TestWriter _printer = new TestWriter(); + + var options = Helpers.Parse(commandLine, _printer); + + Validate(_printer, + new TextAndColor(ConsoleColor.Red, "Error"), + new TextAndColor(ConsoleColor.Black, $": Could not find argument -opt1=value {Environment.NewLine}"), + new TextAndColor(ConsoleColor.Black, "Usage: "), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.White, "testhost.exe"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Green, "Command1"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Cyan, "p1"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Black, "[-"), + new TextAndColor(ConsoleColor.Yellow, "opt1"), + new TextAndColor(ConsoleColor.Black, " value] "), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.White, "testhost.exe"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Green, "Command2"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Cyan, "opt1"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Black, "[-"), + new TextAndColor(ConsoleColor.Yellow, "opt1"), + new TextAndColor(ConsoleColor.Black, " value] "), + new TextAndColor(ConsoleColor.Black, "For detailed information run '"), + new TextAndColor(ConsoleColor.White, "testhost --help"), + new TextAndColor(ConsoleColor.Black, "'.") + ); + } + + [Fact] + public void ErrorWhenNoRequiredParametersInGroupSpecified() + { + // Invalid option should be in exception text + var commandLine = ""; + + TestWriter _printer = new TestWriter(); + + var options = Helpers.Parse(commandLine, _printer); + + Validate(_printer, + new TextAndColor(ConsoleColor.Red, "Error"), + new TextAndColor(ConsoleColor.Black, $": Required parameters have not been specified {Environment.NewLine}"), + new TextAndColor(ConsoleColor.Black, "Usage: "), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.White, "testhost.exe"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Green, "Command1"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Cyan, "p1"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Black, "[-"), + new TextAndColor(ConsoleColor.Yellow, "opt1"), + new TextAndColor(ConsoleColor.Black, " value] "), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.White, "testhost.exe"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Green, "Command2"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Cyan, "opt1"), + new TextAndColor(ConsoleColor.Black, " "), + new TextAndColor(ConsoleColor.Black, "[-"), + new TextAndColor(ConsoleColor.Yellow, "opt1"), + new TextAndColor(ConsoleColor.Black, " value] "), + new TextAndColor(ConsoleColor.Black, "For detailed information run '"), + new TextAndColor(ConsoleColor.White, "testhost --help"), + new TextAndColor(ConsoleColor.Black, "'.") + ); + } } } \ No newline at end of file diff --git a/test/CommandLineTests.Negative.cs b/test/CommandLineTests.Negative.cs index 8236b0f..c01fb7c 100644 --- a/test/CommandLineTests.Negative.cs +++ b/test/CommandLineTests.Negative.cs @@ -1,4 +1,5 @@ -using Xunit; +using System.IO; +using Xunit; namespace CommandLine.Tests { @@ -116,5 +117,11 @@ public void HelpForInvalidType() var options = Helpers.Parse(""); Assert.Null(options); } + + [Fact] + public void MismatchedQuotes() + { + Assert.Throws(() => Helpers.Parse("@\" foo \"")); + } } } \ No newline at end of file