throw CommandParsingException rather than crash on missing single value

This commit is contained in:
jonsequitur 2017-02-03 10:57:57 -08:00
parent f69f0ed266
commit 182c695275
3 changed files with 45 additions and 4 deletions

View 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.");
}
}
}