From 9fd291ef4fd35f4bae8e6a12d9738fdfd4679ae6 Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Tue, 11 Feb 2025 09:56:00 +0100 Subject: [PATCH 1/3] Add tests for help in dotnet test --- .../GivenDotnetTestBuildsAndRunsHelp.cs | 19 +++++++++---------- test/dotnet.Tests/dotnet.Tests.csproj | 1 - 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs index 774632f30ec3..81f73a02f63d 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs @@ -1,7 +1,6 @@ // 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 CommandResult = Microsoft.DotNet.Cli.Utils.CommandResult; namespace Microsoft.DotNet.Cli.Test.Tests @@ -12,8 +11,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) { @@ -26,20 +25,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) @@ -48,13 +48,12 @@ 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 otherTestProjectDllRegex = @$"\s+.*\\{ToolsetInfo.CurrentTargetFramework}\\OtherTestProject\.dll.*\s+--report-trx\s+--report-trx-filename"; - Assert.Matches(@$"Unavailable extension options:(?:({net9ProjectDllRegex})|({net48ProjectExeRegex}))(?:({net48ProjectExeRegex})|({net9ProjectDllRegex}))", result.StdOut); + Assert.Matches(@$"Unavailable extension options:{otherTestProjectDllRegex}", result.StdOut); } result.ExitCode.Should().Be(ExitCodes.Success); diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 97f27447873b..58062b2df585 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -56,7 +56,6 @@ - From cd23c117ac0017faceafa14b96a68a0fefcb8e6d Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Tue, 11 Feb 2025 10:06:46 +0100 Subject: [PATCH 2/3] rename var --- test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs index 81f73a02f63d..cfe811b3425b 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs @@ -1,6 +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 Microsoft.DotNet.Tools.Common; using CommandResult = Microsoft.DotNet.Cli.Utils.CommandResult; namespace Microsoft.DotNet.Cli.Test.Tests @@ -51,7 +52,8 @@ public void RunHelpOnMultipleTestProjects_ShouldReturnZeroAsExitCode(string conf Assert.Matches(@"Extension Options:\s+--[\s\S]*", result.StdOut); Assert.Matches(@"Options:\s+--[\s\S]*", result.StdOut); - string otherTestProjectDllRegex = @$"\s+.*\\{ToolsetInfo.CurrentTargetFramework}\\OtherTestProject\.dll.*\s+--report-trx\s+--report-trx-filename"; + string directorySeparator = PathUtility.GetDirectorySeparatorChar(); + string otherTestProjectDllRegex = @$"\s+.*{directorySeparator}{ToolsetInfo.CurrentTargetFramework}{directorySeparator}OtherTestProject\.dll.*\s+--report-trx\s+--report-trx-filename"; Assert.Matches(@$"Unavailable extension options:{otherTestProjectDllRegex}", result.StdOut); } From e6c7c0862c272e7d113f5c4602752d12517c013e Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Tue, 11 Feb 2025 13:40:48 +0100 Subject: [PATCH 3/3] Fix RunHelpOnMultipleTestProjects_ShouldReturnZeroAsExitCode --- src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs | 2 -- test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs index 40614b5a8a16..e93a8677174b 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -146,8 +146,6 @@ private static CliOption CreateBlameHangDumpOption() private static readonly CliCommand Command = ConstructCommand(); - - public static CliCommand GetCommand() { return Command; diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs index cfe811b3425b..be7b3ecdb08d 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsHelp.cs @@ -53,9 +53,9 @@ public void RunHelpOnMultipleTestProjects_ShouldReturnZeroAsExitCode(string conf Assert.Matches(@"Options:\s+--[\s\S]*", result.StdOut); string directorySeparator = PathUtility.GetDirectorySeparatorChar(); - string otherTestProjectDllRegex = @$"\s+.*{directorySeparator}{ToolsetInfo.CurrentTargetFramework}{directorySeparator}OtherTestProject\.dll.*\s+--report-trx\s+--report-trx-filename"; + 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:{otherTestProjectDllRegex}", result.StdOut); + Assert.Matches(otherTestProjectPattern, result.StdOut); } result.ExitCode.Should().Be(ExitCodes.Success);