dotnet / dotnet/command-line-api

[main] Test has incorrect errors for `-x 1 2 3 4`

Open
#2,392 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

[The test I used to confirm unexpected behavior](https://github.com/dotnet/command-line-api/blob/963d34b1fb712c673bfb198133d7e988182c9ef4/src/System.CommandLine.Tests/ParserTests.cs#L1550)

The test is:

```csharp
[Fact]
public void When_option_arguments_are_greater_than_maximum_arity_then_an_error_is_returned()
{
var command = new CliCommand("the-command")
{
new CliOption("-x") { Arity = new ArgumentArity(2, 3)}
};

var parseResult = CliParser.Parse(command, "-x 1 2 3 4");
parseResult.Errors
.Select(e => e.Message)
.Should()
.Contain(LocalizationResources.UnrecognizedCommandOrArgument("4"));
}
```

I modified the test only to get an interim variable for `parseResult`,

When I do this, the error list is

![image](https://github.com/dotnet/command-line-api/assets/5844318/47b49213-b4d0-43a0-a29e-5663eb80c9a1)

I encountered this because for Powderhouse I encountered issues with options with collection types and I believe I am using the same or funcionally equivalent code - and this test passes. In exploring why my new tests were failing, I realized this test does not appear to be succeeding at what the CLI and the commandline request.

I believe this test should result in a single parse error - an unexpected argument only on the 4.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.