-
Notifications
You must be signed in to change notification settings - Fork 0
Use custom argument parsers for the test args/run settings #1
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
Conversation
| // error. so `dotnet msbuild /t:thing` throws a parse error. | ||
| // .UseParseErrorReporting(127) | ||
| .UseParseErrorReporting("new") | ||
| .UseParseErrorReporting("new", "test") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need test to be part of the new error reporting as well if we want the nice parser errors to be shown to the user. now that we do explicit forwarding of args to commands like MSbuild, we could potentially remove this in favor of the standard UseParseErrorReporting() middleware, but I didn't think that was necessary for your ---removal PR at this time. It can come next :)
| string testSessionCorrelationId = $"{Environment.ProcessId}_{Guid.NewGuid()}"; | ||
|
|
||
| string[] args = parseResult.GetArguments(); | ||
| var args = parseResult.GetValueForArgument(TestCommandParser.ForwardedArgs) ?? Array.Empty<string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic is a lot more understandable - let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really better.
But I think that we can remove ?? Array.Empty<string>() part
| Arity = ArgumentArity.ZeroOrMore | ||
| }; | ||
|
|
||
| private static ParseArgument<(string key, string value)[]> ParseRunSettings = ctx => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok that we don't check double dash? Seems like we can pass dotnet test --logger "trx;logfilename=custom.trx" RunConfiguration.ResultDirectory=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can actually test this now - I should add some tests where we take certain suspicious command lines, run them through the parser, and then do assertions on the parsed arguments. Do you have any specific command lines you'd recommend testing against?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to run GivenDotnetTestBuildsAndRunsTestFromCsproj.ItAcceptsMultipleLoggersAsCliArguments test and it failed. This test was my pain and I remembered it =)
I think problem that System.CommandLine wasn't deployed with dotnet/command-line-api#1759 fix. And I can't find new version in nuget.
Unfortunately I don't use dotnet test very often, so nothing comes to mind =(
But I think that there are only 3 combinations that we should check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. System.CommandLine was updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reproduced problem. Something odd happens when we pass 3 arguments to command and call command with 1 token.
If we call with >1 token then we will get exception from System.CommandLine.
Like this.
I'll create an issue for System.CommandLine team tomorrow
test.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@baronfel just FYI dotnet/command-line-api#1779
|
@baronfel Hi! System.CommandLine team has resolved the issue. I updated the branch with last commit. |
|
Hi @Tunduk - I would like to add some testing for the new parser before this gets merged, but I am currently slammed on personal things at the moment. Do you know of any good examples for commands that use [Theory]
[InlineData(new[]{ "test", "a", b", "\"c=d\""}, "a", new[]{"b"}, new[]{"c=d"})]
public void Can_parse_arbitrary_test_command_line(string[] inputs, string? expectedSlnOrProj, string[] expectedForwardedArgs, string[] expectedRunSettings) {
var parseResult = TestCommandParser.GetCommand().Parse(inputs);
parseResult.GetValueForArgument(TestCommandParser.SolutionOrProjectArgument).Should().Equal(expectedSlnOrProj);
parseResult.GetValueForArgument(TestCommandParser.SolutionOrProjectArgument).Should().SequenceEquals(expectedForwardedArgs);
parseResult.GetValueForArgument(TestCommandParser.InlineRunSettings).Should().SequenceEquals(expectedRunSettings);
}and so on. |
|
Hi @baronfel! If you busy I can add some tests. You are right, this tests shouldn't take a lot of time. |
|
That sounds great to me :) |
This builds on your changes to hopefully remove all of the
---aware logic from the CLI, replacing it with hopefully more user-friendly syntax while not harming backwards compatibility. The idea is that we push a lot of the argument parsing into custom ParseArgument delegates for the two arguments that we're attempting to parse - args to forward to the running application, and runsettings. If we have those captured at parse time, the execution-time logic gets much simpler.