Skip to content

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

Merged
merged 6 commits into from
Jul 14, 2025
Merged

Cleanup dotnet test #49734

merged 6 commits into from
Jul 14, 2025

Conversation

Youssef1313
Copy link
Member

No description provided.

@Copilot Copilot AI review requested due to automatic review settings July 10, 2025 18:31
Copy link
Contributor

@Copilot Copilot AI left a 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 in TestModulesFilterHandler
  • Simplifies argument building in TestApplication and centralizes run command logic
  • Adds validation for RunProperties.RunCommand in SolutionAndProjectUtility and removes fallback in RunProperties

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 with Module.RunProperties.RunArguments ?? string.Empty to guard against null.
        StringBuilder builder = new(Module.RunProperties.RunArguments);

Comment on lines 53 to 57
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));
Copy link
Member Author

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

@Evangelink Evangelink left a 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

@Evangelink Evangelink merged commit 5a684aa into main Jul 14, 2025
27 checks passed
@Evangelink Evangelink deleted the dev/ygerges/cleanup-dotnet-test branch July 14, 2025 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants