Skip to content

Commit 348357b

Browse files
authored
Improve AppendAssemblyResult (#50057)
1 parent 8509ba4 commit 348357b

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/Cli/dotnet/Commands/Test/Terminal/TerminalTestReporter.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -427,28 +427,21 @@ private void AppendExitCodeAndUrl(ITerminal terminal, int? exitCode, bool isRun)
427427
/// <summary>
428428
/// Print a build result summary to the output.
429429
/// </summary>
430-
private static void AppendAssemblyResult(ITerminal terminal, bool succeeded, int countErrors, int countWarnings)
430+
private static void AppendAssemblyResult(ITerminal terminal, TestProgressState state)
431431
{
432-
if (!succeeded)
432+
if (!state.Success)
433433
{
434434
terminal.SetColor(TerminalColor.DarkRed);
435435
// If the build failed, we print one of three red strings.
436-
string text = (countErrors > 0, countWarnings > 0) switch
436+
string text = (state.FailedTests > 0, state.TotalTests == 0) switch
437437
{
438-
(true, true) => string.Format(CultureInfo.CurrentCulture, CliCommandStrings.FailedWithErrorsAndWarnings, countErrors, countWarnings),
439-
(true, _) => string.Format(CultureInfo.CurrentCulture, CliCommandStrings.FailedWithErrors, countErrors),
440-
(false, true) => string.Format(CultureInfo.CurrentCulture, CliCommandStrings.FailedWithWarnings, countWarnings),
441-
_ => CliCommandStrings.FailedLowercase,
438+
(true, _) => string.Format(CultureInfo.CurrentCulture, CliCommandStrings.FailedWithErrors, state.FailedTests),
439+
(false, true) => CliCommandStrings.ZeroTestsRan,
440+
(false, false) => CliCommandStrings.FailedLowercase,
442441
};
443442
terminal.Append(text);
444443
terminal.ResetColor();
445444
}
446-
else if (countWarnings > 0)
447-
{
448-
terminal.SetColor(TerminalColor.DarkYellow);
449-
terminal.Append($"succeeded with {countWarnings} warning(s)");
450-
terminal.ResetColor();
451-
}
452445
else
453446
{
454447
terminal.SetColor(TerminalColor.DarkGreen);
@@ -858,12 +851,10 @@ void AppendOutputWhenPresent(string description, string? output)
858851
private static void AppendAssemblySummary(TestProgressState assemblyRun, ITerminal terminal)
859852
{
860853
terminal.ResetColor();
861-
int failedTests = assemblyRun.FailedTests;
862-
int warnings = 0;
863-
854+
864855
AppendAssemblyLinkTargetFrameworkAndArchitecture(terminal, assemblyRun.Assembly, assemblyRun.TargetFramework, assemblyRun.Architecture);
865856
terminal.Append(' ');
866-
AppendAssemblyResult(terminal, assemblyRun.Success, failedTests, warnings);
857+
AppendAssemblyResult(terminal, assemblyRun);
867858
terminal.Append(' ');
868859
AppendLongDuration(terminal, assemblyRun.Stopwatch.Elapsed);
869860
terminal.AppendLine();

test/Microsoft.NET.TestFramework/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal static class TestingConstants
1010

1111
public const string Failed = "failed";
1212
public const string Passed = "passed";
13+
public const string ZeroTestsRan = "Zero tests ran";
1314
}
1415

1516
internal static class ExitCode

test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void RunMultipleTestProjectsWithDifferentFailures_ShouldReturnExitCodeGen
225225

226226
if (!TestContext.IsLocalized())
227227
{
228-
Assert.Matches(RegexPatternHelper.GenerateProjectRegexPattern("TestProject", TestingConstants.Failed, true, configuration, "8"), result.StdOut);
228+
Assert.Matches(RegexPatternHelper.GenerateProjectRegexPattern("TestProject", TestingConstants.ZeroTestsRan, true, configuration, "8"), result.StdOut);
229229
Assert.Matches(RegexPatternHelper.GenerateProjectRegexPattern("OtherTestProject", TestingConstants.Failed, true, configuration, "2"), result.StdOut);
230230
Assert.Matches(RegexPatternHelper.GenerateProjectRegexPattern("AnotherTestProject", TestingConstants.Failed, true, configuration, "9"), result.StdOut);
231231

0 commit comments

Comments
 (0)