throw CommandParsingException rather than crash on missing single value
This commit is contained in:
parent
f69f0ed266
commit
182c695275
3 changed files with 45 additions and 4 deletions
26
test/dotnet.Tests/CommandLineApplicationTests.cs
Normal file
26
test/dotnet.Tests/CommandLineApplicationTests.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tests
|
||||
{
|
||||
public class CommandLineApplicationTests
|
||||
{
|
||||
[Fact]
|
||||
public void WhenAnOptionRequiresASingleValueThatIsNotSuppliedItThrowsCommandParsingException()
|
||||
{
|
||||
var app = new CommandLineApplication();
|
||||
|
||||
app.Option("-v|--verbosity", "be verbose", CommandOptionType.SingleValue);
|
||||
|
||||
Action execute = () => app.Execute("-v");
|
||||
|
||||
execute.ShouldThrow<CommandParsingException>()
|
||||
.Which
|
||||
.Message
|
||||
.Should()
|
||||
.Be("Required value for option '-v' was not provided.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue