Skip to content

Commit b6eee93

Browse files
Add tests for help in dotnet test (#46715)
1 parent 2499ae8 commit b6eee93

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ private static CliOption<string> CreateBlameHangDumpOption()
146146

147147
private static readonly CliCommand Command = ConstructCommand();
148148

149-
150-
151149
public static CliCommand GetCommand()
152150
{
153151
return Command;

test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using dotnet.Tests;
4+
using Microsoft.DotNet.Tools.Common;
55
using CommandResult = Microsoft.DotNet.Cli.Utils.CommandResult;
66

77
namespace Microsoft.DotNet.Cli.Test.Tests
@@ -12,8 +12,8 @@ public GivenDotnetTestBuildsAndRunsHelp(ITestOutputHelper log) : base(log)
1212
{
1313
}
1414

15-
[InlineData(Constants.Debug)]
16-
[InlineData(Constants.Release)]
15+
[InlineData(TestingConstants.Debug)]
16+
[InlineData(TestingConstants.Release)]
1717
[Theory]
1818
public void RunHelpOnTestProject_ShouldReturnZeroAsExitCode(string configuration)
1919
{
@@ -26,20 +26,21 @@ public void RunHelpOnTestProject_ShouldReturnZeroAsExitCode(string configuration
2626

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

3333
result.ExitCode.Should().Be(ExitCodes.Success);
3434
}
3535

36-
[InlineData(Constants.Debug)]
37-
[InlineData(Constants.Release)]
36+
[InlineData(TestingConstants.Debug)]
37+
[InlineData(TestingConstants.Release)]
3838
[Theory]
3939
public void RunHelpOnMultipleTestProjects_ShouldReturnZeroAsExitCode(string configuration)
4040
{
4141
TestAsset testInstance = _testAssetsManager.CopyTestAsset("ProjectSolutionForMultipleTFMs", Guid.NewGuid().ToString())
4242
.WithSource();
43+
testInstance.WithTargetFramework($"{DotnetVersionHelper.GetPreviousDotnetVersion()}", "TestProject");
4344

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

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

54-
string net9ProjectDllRegex = @"\s+.*\\net9\.0\\TestProjectWithNet9\.dll.*\s+--report-trx\s+--report-trx-filename";
55-
string net48ProjectExeRegex = @"\s+.*\\net4\.8\\TestProjectWithNetFramework\.exe.*\s+--report-trx\s+--report-trx-filename";
55+
string directorySeparator = PathUtility.GetDirectorySeparatorChar();
56+
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)";
5657

57-
Assert.Matches(@$"Unavailable extension options:(?:({net9ProjectDllRegex})|({net48ProjectExeRegex}))(?:({net48ProjectExeRegex})|({net9ProjectDllRegex}))", result.StdOut);
58+
Assert.Matches(otherTestProjectPattern, result.StdOut);
5859
}
5960

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

test/dotnet.Tests/dotnet.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
<Compile Include="..\Microsoft.DotNet.CommandFactory.Tests\**\*.cs" LinkBase="CommandFactory" />
5757
<Compile Include="..\Microsoft.DotNet.Configurer.UnitTests\**\*.cs" LinkBase="Configurer" />
5858
<Compile Include="..\Microsoft.DotNet.ShellShim.Tests\**\*.cs" LinkBase="ShellShim" />
59-
<Compile Remove="..\dotnet-test.Tests\GivenDotnetTestBuildsAndRunsHelp.cs" />
6059
<Compile Remove="..\dotnet-test.Tests\MSBuildHandlerTests.cs" />
6160

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

0 commit comments

Comments
 (0)