Skip to content
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

Add tests for help in dotnet test #46715

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ private static CliOption<string> CreateBlameHangDumpOption()

private static readonly CliCommand Command = ConstructCommand();



public static CliCommand GetCommand()
{
return Command;
Expand Down
21 changes: 11 additions & 10 deletions test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using dotnet.Tests;
using Microsoft.DotNet.Tools.Common;
using CommandResult = Microsoft.DotNet.Cli.Utils.CommandResult;

namespace Microsoft.DotNet.Cli.Test.Tests
Expand All @@ -12,8 +12,8 @@ public GivenDotnetTestBuildsAndRunsHelp(ITestOutputHelper log) : base(log)
{
}

[InlineData(Constants.Debug)]
[InlineData(Constants.Release)]
[InlineData(TestingConstants.Debug)]
[InlineData(TestingConstants.Release)]
[Theory]
public void RunHelpOnTestProject_ShouldReturnZeroAsExitCode(string configuration)
{
Expand All @@ -26,20 +26,21 @@ public void RunHelpOnTestProject_ShouldReturnZeroAsExitCode(string configuration

if (!TestContext.IsLocalized())
{
Assert.Matches(@"Extension options:\s+--[\s\S]*", result.StdOut);
Assert.Matches(@"Extension Options:\s+--[\s\S]*", result.StdOut);
Assert.Matches(@"Options:\s+--[\s\S]*", result.StdOut);
}

result.ExitCode.Should().Be(ExitCodes.Success);
}

[InlineData(Constants.Debug)]
[InlineData(Constants.Release)]
[InlineData(TestingConstants.Debug)]
[InlineData(TestingConstants.Release)]
[Theory]
public void RunHelpOnMultipleTestProjects_ShouldReturnZeroAsExitCode(string configuration)
{
TestAsset testInstance = _testAssetsManager.CopyTestAsset("ProjectSolutionForMultipleTFMs", Guid.NewGuid().ToString())
.WithSource();
testInstance.WithTargetFramework($"{DotnetVersionHelper.GetPreviousDotnetVersion()}", "TestProject");

CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
.WithWorkingDirectory(testInstance.Path)
Expand All @@ -48,13 +49,13 @@ public void RunHelpOnMultipleTestProjects_ShouldReturnZeroAsExitCode(string conf

if (!TestContext.IsLocalized())
{
Assert.Matches(@"Extension options:\s+--[\s\S]*", result.StdOut);
Assert.Matches(@"Extension Options:\s+--[\s\S]*", result.StdOut);
Assert.Matches(@"Options:\s+--[\s\S]*", result.StdOut);

string net9ProjectDllRegex = @"\s+.*\\net9\.0\\TestProjectWithNet9\.dll.*\s+--report-trx\s+--report-trx-filename";
string net48ProjectExeRegex = @"\s+.*\\net4\.8\\TestProjectWithNetFramework\.exe.*\s+--report-trx\s+--report-trx-filename";
string directorySeparator = PathUtility.GetDirectorySeparatorChar();
string otherTestProjectPattern = @$"Unavailable extension options:\s+.*{directorySeparator}{ToolsetInfo.CurrentTargetFramework}{directorySeparator}OtherTestProject\.dll.*\s+(--report-trx\s+--report-trx-filename|--report-trx-filename\s+--report-trx)";

Assert.Matches(@$"Unavailable extension options:(?:({net9ProjectDllRegex})|({net48ProjectExeRegex}))(?:({net48ProjectExeRegex})|({net9ProjectDllRegex}))", result.StdOut);
Assert.Matches(otherTestProjectPattern, result.StdOut);
}

result.ExitCode.Should().Be(ExitCodes.Success);
Expand Down
1 change: 0 additions & 1 deletion test/dotnet.Tests/dotnet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<Compile Include="..\Microsoft.DotNet.CommandFactory.Tests\**\*.cs" LinkBase="CommandFactory" />
<Compile Include="..\Microsoft.DotNet.Configurer.UnitTests\**\*.cs" LinkBase="Configurer" />
<Compile Include="..\Microsoft.DotNet.ShellShim.Tests\**\*.cs" LinkBase="ShellShim" />
<Compile Remove="..\dotnet-test.Tests\GivenDotnetTestBuildsAndRunsHelp.cs" />
<Compile Remove="..\dotnet-test.Tests\MSBuildHandlerTests.cs" />

<None Include="..\Microsoft.DotNet.ShellShim.Tests\WpfBinaryTestAsssets\testwpf.dll" LinkBase="WpfBinaryTestAsssets">
Expand Down