-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add better error messages for dotnet test with solution/project/directory/dll arguments in Microsoft.Testing.Platform (MTP) #50108
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
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b543e91
Initial plan
Copilot 17a9f57
Implement better error messages for dotnet test with file/directory a…
Copilot 455bd3b
Add validation logic for MTP command to provide better error messages…
Copilot 8c23e19
Revert all changes to TestCommand.cs as requested by review feedback
Copilot c915df9
Cleanup
Youssef1313 efa5c92
Cleanup
Youssef1313 480aa2b
Assert english strings only when non-localized
Youssef1313 5d6eab3
Fix grammar error: change "Specifying a dlls" to "Specifying dlls" in…
Copilot 74f5993
Update TestCommandValidationTests.cs
Youssef1313 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
test/dotnet.Tests/CommandTests/Test/TestCommandValidationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.DotNet.Tools.Test.Utilities; | ||
|
||
namespace Microsoft.DotNet.Cli.Test.Tests | ||
{ | ||
public class TestCommandValidationTests : SdkTest | ||
{ | ||
public TestCommandValidationTests(ITestOutputHelper log) : base(log) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[InlineData("MySolution.sln", "Solution file 'MySolution.sln' was provided as a positional argument.")] | ||
[InlineData("MyProject.csproj", "Project file 'MyProject.csproj' was provided as a positional argument.")] | ||
[InlineData("MyProject.vbproj", "Project file 'MyProject.vbproj' was provided as a positional argument.")] | ||
[InlineData("MyProject.fsproj", "Project file 'MyProject.fsproj' was provided as a positional argument.")] | ||
public void TestCommandShouldValidateFileArgumentsAndProvideHelpfulMessages(string filename, string expectedErrorStart) | ||
{ | ||
var testDir = _testAssetsManager.CreateTestDirectory(); | ||
|
||
// Create the test file | ||
var testFilePath = Path.Combine(testDir.Path, filename); | ||
File.WriteAllText(testFilePath, "dummy content"); | ||
|
||
var result = new DotnetTestCommand(Log, disableNewOutput: true) | ||
.WithWorkingDirectory(testDir.Path) | ||
.Execute(filename); | ||
|
||
result.ExitCode.Should().Be(1); | ||
result.StdErr.Should().Contain(expectedErrorStart); | ||
result.StdErr.Should().Contain("Testing Platform"); | ||
result.StdErr.Should().Contain("dotnet.config"); | ||
} | ||
|
||
[Fact] | ||
public void TestCommandShouldValidateDirectoryArgumentAndProvideHelpfulMessage() | ||
{ | ||
var testDir = _testAssetsManager.CreateTestDirectory(); | ||
var subDir = Path.Combine(testDir.Path, "test_directory"); | ||
Directory.CreateDirectory(subDir); | ||
|
||
var result = new DotnetTestCommand(Log, disableNewOutput: true) | ||
.WithWorkingDirectory(testDir.Path) | ||
.Execute("test_directory"); | ||
|
||
result.ExitCode.Should().Be(1); | ||
result.StdErr.Should().Contain("Directory 'test_directory' was provided as a positional argument."); | ||
result.StdErr.Should().Contain("--directory test_directory"); | ||
result.StdErr.Should().Contain("Testing Platform"); | ||
} | ||
|
||
[Fact] | ||
public void TestCommandShouldValidateDllArgumentAndProvideHelpfulMessage() | ||
{ | ||
var testDir = _testAssetsManager.CreateTestDirectory(); | ||
|
||
// Create a dummy dll file | ||
var dllPath = Path.Combine(testDir.Path, "test.dll"); | ||
File.WriteAllText(dllPath, "dummy dll content"); | ||
|
||
var result = new DotnetTestCommand(Log, disableNewOutput: true) | ||
.WithWorkingDirectory(testDir.Path) | ||
.Execute("test.dll"); | ||
|
||
result.ExitCode.Should().Be(1); | ||
result.StdErr.Should().Contain("Test assembly 'test.dll' was provided as a positional argument."); | ||
result.StdErr.Should().Contain("--test-modules test.dll"); | ||
result.StdErr.Should().Contain("Testing Platform"); | ||
} | ||
|
||
[Fact] | ||
public void TestCommandShouldAllowNormalOptionsWithoutValidation() | ||
{ | ||
var testDir = _testAssetsManager.CreateTestDirectory(); | ||
|
||
// Test that normal options like --help still work without triggering validation | ||
var result = new DotnetTestCommand(Log, disableNewOutput: true) | ||
.Execute("--help"); | ||
|
||
result.ExitCode.Should().Be(0); | ||
result.StdOut.Should().Contain("Usage:"); | ||
result.StdOut.Should().Contain("dotnet test"); | ||
} | ||
|
||
[Fact] | ||
public void TestCommandShouldNotValidateNonExistentFiles() | ||
{ | ||
var testDir = _testAssetsManager.CreateTestDirectory(); | ||
|
||
// Test that non-existent files with project extensions don't trigger validation | ||
var result = new DotnetTestCommand(Log, disableNewOutput: true) | ||
.WithWorkingDirectory(testDir.Path) | ||
.Execute("NonExistent.csproj"); | ||
|
||
// This should pass through to MSBuild and give a different error, not our validation error | ||
result.ExitCode.Should().Be(1); | ||
result.StdErr.Should().NotContain("was provided as a positional argument"); | ||
result.StdErr.Should().NotContain("Testing Platform"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.