Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate that the error message when an invalid argument is passed co… #39

Merged
merged 4 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions test/CommandLineTests.Help.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Groups1>(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<Groups1>(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, "'.")
);
}
}
}
9 changes: 8 additions & 1 deletion test/CommandLineTests.Negative.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit;
using System.IO;
using Xunit;

namespace CommandLine.Tests
{
Expand Down Expand Up @@ -116,5 +117,11 @@ public void HelpForInvalidType()
var options = Helpers.Parse<object>("");
Assert.Null(options);
}

[Fact]
public void MismatchedQuotes()
{
Assert.Throws<InvalidDataException>(() => Helpers.Parse<object>("@\" foo \""));
}
}
}