-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cleanup dotnet test #49734
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
Cleanup dotnet test #49734
Conversation
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.
Pull Request Overview
This PR refactors how test modules and applications construct their RunProperties
, removes legacy fallback logic in RunProperties
, and adds validation to ensure test commands are executable.
- Introduces conditional creation of
RunProperties
inTestModulesFilterHandler
- Simplifies argument building in
TestApplication
and centralizes run command logic - Adds validation for
RunProperties.RunCommand
inSolutionAndProjectUtility
and removes fallback inRunProperties
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/Cli/dotnet/Commands/Test/TestModulesFilterHandler.cs | New conditional logic for DLL vs. executable modules |
src/Cli/dotnet/Commands/Test/TestApplication.cs | Consolidated process start info and removed old argument helpers |
src/Cli/dotnet/Commands/Test/SolutionAndProjectUtility.cs | Throws when run command is missing or a DLL, no longer falls back |
src/Cli/dotnet/Commands/Run/RunProperties.cs | Removed fallback-to-target-path logic |
src/Cli/dotnet/Commands/Run/RunCommand.cs | Updated to call FromProjectAndApplicationArguments without fallback |
Comments suppressed due to low confidence (2)
src/Cli/dotnet/Commands/Test/SolutionAndProjectUtility.cs:233
- New exception path for missing or DLL
RunCommand
should be covered by unit tests to ensure correct behavior when encountering libraries or empty commands.
if (string.IsNullOrEmpty(runProperties.RunCommand) || runProperties.RunCommand.HasExtension(CliConstants.DLLExtension))
src/Cli/dotnet/Commands/Test/TestApplication.cs:93
- If
Module.RunProperties.RunArguments
is null,new StringBuilder(null)
will throw an exception. Initialize withModule.RunProperties.RunArguments ?? string.Empty
to guard against null.
StringBuilder builder = new(Module.RunProperties.RunArguments);
RunProperties runProperties = testModule.HasExtension(CliConstants.DLLExtension) | ||
? new RunProperties(new Muxer().MuxerPath, $@"exec ""{testModule}""", null) | ||
: new RunProperties(testModule, null, null); | ||
|
||
var testApp = new ParallelizableTestModuleGroupWithSequentialInnerModules(new TestModule(runProperties, null, null, true, true, null)); |
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.
Instead of letting TestApplication
class be concerned about whether the data is coming through module filter (by checking if it's dll), I think it's better to just provide the correct RunProperties
from the beginning.
Note that I'm here now using new Muxer().MuxerPath
, where previously we used Environment.ProcessPath
. @elinor-fung @baronfel @dsplaisted Can you please clarify when new Muxer().MuxerPath
is different from Environment.ProcessPath
and which one is the correct one to use?
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.
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 the cases where it is different is when we are running tests of the .NET CLI itself, so dotnet.dll gets loaded as a dependency of our tests instead of as the main application.
They might also be different if the new paths
feature of global.json is used, in that case I think the process path could be under program files, while it would load a local copy of dotnet.dll and so the MuxerPath would be relative to that.
I'm not sure if there are other scenarios where it would be different.
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.
@dsplaisted Hmm, so for the purpose of running an assembly using dotnet exec
while running dotnet test
, which one of the two should be the right one?
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.
Most of your comments would be useful as code comment
No description provided.