Skip to content

Commit 861d938

Browse files
CopilotYoussef1313
andauthored
Fix test duration display to not show "(0ms)" when duration is unavailable (#51792)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Youssef1313 <[email protected]> Co-authored-by: Youssef Victor <[email protected]>
1 parent 81487e5 commit 861d938

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
22

33
using System.Collections.Concurrent;
4-
using Microsoft.TemplateEngine.Cli.Help;
54
using System.Globalization;
65
using System.Text.RegularExpressions;
76
using Microsoft.CodeAnalysis;
8-
using Microsoft.Testing.Platform.OutputDevice.Terminal;
97
using Microsoft.DotNet.Cli.Commands.Test.IPC.Models;
8+
using Microsoft.TemplateEngine.Cli.Help;
9+
using Microsoft.Testing.Platform.OutputDevice.Terminal;
1010

1111
namespace Microsoft.DotNet.Cli.Commands.Test.Terminal;
1212

@@ -397,7 +397,7 @@ internal void TestCompleted(
397397
string displayName,
398398
string? informativeMessage,
399399
TestOutcome outcome,
400-
TimeSpan duration,
400+
TimeSpan? duration,
401401
FlatException[]? exceptions,
402402
string? expected,
403403
string? actual,
@@ -458,7 +458,7 @@ internal void TestCompleted(
458458
string displayName,
459459
string? informativeMessage,
460460
TestOutcome outcome,
461-
TimeSpan duration,
461+
TimeSpan? duration,
462462
FlatException[]? flatExceptions,
463463
string? expected,
464464
string? actual,
@@ -496,9 +496,12 @@ internal void TestCompleted(
496496
terminal.ResetColor();
497497
terminal.Append(' ');
498498
terminal.Append(displayName);
499-
terminal.SetColor(TerminalColor.DarkGray);
500-
terminal.Append(' ');
501-
AppendLongDuration(terminal, duration);
499+
500+
if (duration.HasValue)
501+
{
502+
terminal.Append(' ');
503+
AppendLongDuration(terminal, duration.Value);
504+
}
502505

503506
if (!string.IsNullOrEmpty(informativeMessage))
504507
{

src/Cli/dotnet/Commands/Test/MTP/TestApplicationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ internal void OnTestResultsReceived(TestResultMessages testResultMessage)
143143
testResult.DisplayName!,
144144
testResult.Reason,
145145
ToOutcome(testResult.State),
146-
TimeSpan.FromTicks(testResult.Duration ?? 0),
146+
testResult.Duration.HasValue ? TimeSpan.FromTicks(testResult.Duration.Value) : null,
147147
exceptions: null,
148148
expected: null,
149149
actual: null,
@@ -158,7 +158,7 @@ internal void OnTestResultsReceived(TestResultMessages testResultMessage)
158158
testResult.DisplayName!,
159159
testResult.Reason,
160160
ToOutcome(testResult.State),
161-
TimeSpan.FromTicks(testResult.Duration ?? 0),
161+
testResult.Duration.HasValue ? TimeSpan.FromTicks(testResult.Duration.Value) : null,
162162
exceptions: [.. testResult.Exceptions!.Select(fe => new Terminal.FlatException(fe.ErrorMessage, fe.ErrorType, fe.StackTrace))],
163163
expected: null,
164164
actual: null,

0 commit comments

Comments
 (0)