Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,62 @@ public void AppendTestWorkerProgress(TestProgressState progress, RenderedProgres

int nonReservedWidth = Width - (durationString.Length + 2);

int discovered = progress.DiscoveredTests;
int passed = progress.PassedTests;
int failed = progress.FailedTests;
int skipped = progress.SkippedTests;
int charsTaken = 0;

terminal.Append('[');
charsTaken++;
terminal.SetColor(TerminalColor.DarkGreen);
terminal.Append('✓');
charsTaken++;
string passedText = passed.ToString(CultureInfo.CurrentCulture);
terminal.Append(passedText);
charsTaken += passedText.Length;
terminal.ResetColor();

terminal.Append('/');
charsTaken++;

terminal.SetColor(TerminalColor.DarkRed);
terminal.Append('x');
charsTaken++;
string failedText = failed.ToString(CultureInfo.CurrentCulture);
terminal.Append(failedText);
charsTaken += failedText.Length;
terminal.ResetColor();

terminal.Append('/');
charsTaken++;

terminal.SetColor(TerminalColor.DarkYellow);
terminal.Append('↓');
charsTaken++;
string skippedText = skipped.ToString(CultureInfo.CurrentCulture);
terminal.Append(skippedText);
charsTaken += skippedText.Length;
terminal.ResetColor();
terminal.Append(']');
charsTaken++;
if (!progress.IsDiscovery)
{
terminal.Append('[');
charsTaken++;
terminal.SetColor(TerminalColor.DarkGreen);
terminal.Append('✓');
charsTaken++;
string passedText = passed.ToString(CultureInfo.CurrentCulture);
terminal.Append(passedText);
charsTaken += passedText.Length;
terminal.ResetColor();

terminal.Append('/');
charsTaken++;

terminal.SetColor(TerminalColor.DarkRed);
terminal.Append('x');
charsTaken++;
string failedText = failed.ToString(CultureInfo.CurrentCulture);
terminal.Append(failedText);
charsTaken += failedText.Length;
terminal.ResetColor();

terminal.Append('/');
charsTaken++;

terminal.SetColor(TerminalColor.DarkYellow);
terminal.Append('↓');
charsTaken++;
string skippedText = skipped.ToString(CultureInfo.CurrentCulture);
terminal.Append(skippedText);
charsTaken += skippedText.Length;
terminal.ResetColor();
terminal.Append(']');
charsTaken++;
}
else
{
string discoveredText = discovered.ToString(CultureInfo.CurrentCulture);
terminal.Append('[');
charsTaken++;
terminal.SetColor(TerminalColor.DarkMagenta);
terminal.Append('+');
charsTaken++;
terminal.Append(discoveredText);
charsTaken += discoveredText.Length;
terminal.ResetColor();
terminal.Append(']');
charsTaken++;
}

terminal.Append(' ');
charsTaken++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,48 @@ public void RenderProgress(TestProgressState?[] progress)

string durationString = HumanReadableDurationFormatter.Render(p.Stopwatch.Elapsed);

int discovered = p.DiscoveredTests;
int passed = p.PassedTests;
int failed = p.FailedTests;
int skipped = p.SkippedTests;

// Use just ascii here, so we don't put too many restrictions on fonts needing to
// properly show unicode, or logs being saved in particular encoding.
Append('[');
SetColor(TerminalColor.DarkGreen);
Append('+');
Append(passed.ToString(CultureInfo.CurrentCulture));
ResetColor();

Append('/');

SetColor(TerminalColor.DarkRed);
Append('x');
Append(failed.ToString(CultureInfo.CurrentCulture));
ResetColor();

Append('/');

SetColor(TerminalColor.DarkYellow);
Append('?');
Append(skipped.ToString(CultureInfo.CurrentCulture));
ResetColor();
Append(']');
if (!p.IsDiscovery)
{
// Use just ascii here, so we don't put too many restrictions on fonts needing to
// properly show unicode, or logs being saved in particular encoding.
Append('[');
SetColor(TerminalColor.DarkGreen);
Append('+');
Append(passed.ToString(CultureInfo.CurrentCulture));
ResetColor();

Append('/');

SetColor(TerminalColor.DarkRed);
Append('x');
Append(failed.ToString(CultureInfo.CurrentCulture));
ResetColor();

Append('/');

SetColor(TerminalColor.DarkYellow);
Append('?');
Append(skipped.ToString(CultureInfo.CurrentCulture));
ResetColor();
Append(']');
}
else
{
// Use just ascii here, so we don't put too many restrictions on fonts needing to
// properly show unicode, or logs being saved in particular encoding.
Append('[');
SetColor(TerminalColor.DarkMagenta);
Append('+');
Append(discovered.ToString(CultureInfo.CurrentCulture));
ResetColor();

Append(']');
}

Append(' ');
Append(p.AssemblyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private TestProgressState GetOrAddAssemblyRun()
}

IStopwatch sw = CreateStopwatch();
var assemblyRun = new TestProgressState(Interlocked.Increment(ref _counter), _assembly, _targetFramework, _architecture, sw);
var assemblyRun = new TestProgressState(Interlocked.Increment(ref _counter), _assembly, _targetFramework, _architecture, sw, _isDiscovery);
int slotIndex = _terminalWithProgress.AddWorker(assemblyRun);
assemblyRun.SlotIndex = slotIndex;
_testProgressState = assemblyRun;
Expand Down Expand Up @@ -840,11 +840,12 @@ internal void TestDiscovered(string displayName)
}

TestProgressState asm = _testProgressState;
asm.DiscoveredTests++;

if (_isDiscovery)
{
// TODO: add mode for discovered tests to the progress bar, to get rid of the hack here that allows updating the
// progress, but also breaks the total counts if not done only in discovery.
asm.PassedTests++;
// In discovery mode we count discovered tests,
// but in execution mode the completion of test will increase the total tests count.
asm.TotalTests++;
}

Expand All @@ -859,7 +860,7 @@ public void AppendTestDiscoverySummary(ITerminal terminal)
terminal.AppendLine();

int totalTests = assembly?.TotalTests ?? 0;
bool runFailed = WasCancelled;
bool runFailed = WasCancelled || totalTests < 1;

if (assembly is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

internal sealed class TestProgressState
{
public TestProgressState(long id, string assembly, string? targetFramework, string? architecture, IStopwatch stopwatch)
public TestProgressState(long id, string assembly, string? targetFramework, string? architecture, IStopwatch stopwatch, bool isDiscovery)
{
Id = id;
Assembly = assembly;
TargetFramework = targetFramework;
Architecture = architecture;
Stopwatch = stopwatch;
AssemblyName = Path.GetFileName(assembly)!;
IsDiscovery = isDiscovery;
}

public string Assembly { get; }
Expand All @@ -27,6 +28,8 @@ public TestProgressState(long id, string assembly, string? targetFramework, stri

public IStopwatch Stopwatch { get; }

public int DiscoveredTests { get; internal set; }

public List<IProgressMessage> Messages { get; } = [];

public int FailedTests { get; internal set; }
Expand All @@ -47,6 +50,8 @@ public TestProgressState(long id, string assembly, string? targetFramework, stri

public List<string> DiscoveredTestDisplayNames { get; internal set; } = [];

public bool IsDiscovery { get; }

internal void AddError(string text)
=> Messages.Add(new ErrorMessage(text));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,4 +755,62 @@ public void TestDiscovery_WithControlCharacters_AreNormalized(char controlChar,
Assert.DoesNotContain(literalDisplayName, output, $"Literal {charName} should not be present in test display name");
}
}

[TestMethod]
public void TestProgressState_WhenCreatedWithDiscoveryTrue_ShouldHaveIsDiscoveryTrue()
{
// Arrange
var stopwatch = new StopwatchFactory.MockStopwatch(new StopwatchFactory(), TimeSpan.Zero);

// Act
var progressState = new TestProgressState(1, "test.dll", "net8.0", "x64", stopwatch, isDiscovery: true);

// Assert
Assert.IsTrue(progressState.IsDiscovery);
Assert.AreEqual(0, progressState.DiscoveredTests);
}

[TestMethod]
public void TestProgressState_WhenCreatedWithFalseIsDiscoveryParameter_ShouldHaveIsDiscoveryFalse()
{
// Arrange
var stopwatch = new StopwatchFactory.MockStopwatch(new StopwatchFactory(), TimeSpan.Zero);

// Act
var progressState = new TestProgressState(1, "test.dll", "net8.0", "x64", stopwatch, isDiscovery: false);

// Assert
Assert.IsFalse(progressState.IsDiscovery);
Assert.AreEqual(0, progressState.DiscoveredTests);
}

[TestMethod]
public void TerminalTestReporter_WhenInDiscoveryMode_ShouldIncrementDiscoveredTests()
{
// Arrange
string assembly = "test.dll";
var stringBuilderConsole = new StringBuilderConsole();
var terminalReporter = new TerminalTestReporter(assembly, "net8.0", "x64", stringBuilderConsole, new CTRLPlusCCancellationTokenSource(), new TerminalTestReporterOptions
{
ShowPassedTests = () => false,
UseAnsi = false,
ShowProgress = () => false,
});

DateTimeOffset startTime = DateTimeOffset.MinValue;
DateTimeOffset endTime = DateTimeOffset.MaxValue;

// Act
terminalReporter.TestExecutionStarted(startTime, 1, isDiscovery: true);
terminalReporter.AssemblyRunStarted();
terminalReporter.TestDiscovered("TestMethod1");
terminalReporter.TestDiscovered("TestMethod2");
terminalReporter.AssemblyRunCompleted();
terminalReporter.TestExecutionCompleted(endTime);

string output = stringBuilderConsole.Output;

// Assert - should contain information about 2 tests discovered
Assert.IsTrue(output.Contains('2') || output.Contains("TestMethod1"), "Output should contain information about discovered tests");
}
}