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
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Testing.Platform.OutputDevice;

internal interface IHotReloadPlatformOutputDevice : IPlatformOutputDevice
Comment thread
Evangelink marked this conversation as resolved.
{
Task DisplayBeforeHotReloadSessionStartAsync();

Task DisplayAfterHotReloadSessionEndAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ public void Render(AnsiTerminalTestProgressFrame previousFrame, AnsiTerminal ter
terminal.MoveCursorUp(previousFrame.ProgressCount + 2);
}

terminal.AppendLine();
// When there is nothing to render, don't write empty lines, e.g. when we start the test run, and then we kick off build
// in dotnet test, there is a long pause where we have no assemblies and no test results (yet).
if (ProgressCount > 0)
{
terminal.AppendLine();
}

int i = 0;
for (; i < ProgressCount; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal sealed partial class TerminalTestReporter : IDisposable

private bool _wasCancelled;

private bool? _shouldShowPassedTests;

#if NET7_0_OR_GREATER
[GeneratedRegex(@$"^ at ((?<code>.+) in (?<file>.+):line (?<line>\d+)|(?<code1>.+))$", RegexOptions.ExplicitCapture, 1000)]
private static partial Regex GetFrameRegex();
Expand Down Expand Up @@ -399,7 +401,7 @@ internal void TestCompleted(
}

_terminalWithProgress.UpdateWorker(asm.SlotIndex);
if (outcome != TestOutcome.Passed || _options.ShowPassedTests)
if (outcome != TestOutcome.Passed || GetShowPassedTests())
{
_terminalWithProgress.WriteToTerminal(terminal => RenderTestCompleted(
terminal,
Expand All @@ -416,6 +418,12 @@ internal void TestCompleted(
}
}

private bool GetShowPassedTests()
{
_shouldShowPassedTests ??= _options.ShowPassedTests();
return _shouldShowPassedTests.Value;
}

internal /* for testing */ void RenderTestCompleted(
ITerminal terminal,
string assembly,
Expand All @@ -429,7 +437,7 @@ internal void TestCompleted(
string? expected,
string? actual)
{
if (outcome == TestOutcome.Passed && !_options.ShowPassedTests)
if (outcome == TestOutcome.Passed && !GetShowPassedTests())
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed class TerminalTestReporterOptions
/// <summary>
/// Gets a value indicating whether we should show passed tests.
/// </summary>
public bool ShowPassedTests { get; init; }
public Func<bool> ShowPassedTests { get; init; } = () => true;

/// <summary>
/// Gets a value indicating whether we should show information about which assembly is the source of the data on screen. Turn this off when running directly from an exe to reduce noise, because the path will always be the same.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Microsoft.Testing.Platform.OutputDevice;
/// <summary>
/// Implementation of output device that writes to terminal with progress and optionally with ANSI.
/// </summary>
internal partial class TerminalOutputDevice : IPlatformOutputDevice,
internal partial class TerminalOutputDevice : IHotReloadPlatformOutputDevice,
IDataConsumer,
IOutputDeviceDataProducer,
ITestSessionLifetimeHandler,
Expand Down Expand Up @@ -123,11 +123,16 @@ public Task InitializeAsync()
bool noAnsi = _commandLineOptions.IsOptionSet(TerminalTestReporterCommandLineOptionsProvider.NoAnsiOption);
bool noProgress = _commandLineOptions.IsOptionSet(TerminalTestReporterCommandLineOptionsProvider.NoProgressOption);

bool showPassed = false;
// _runtimeFeature.IsHotReloadEnabled is not set to true here, even if the session will be HotReload,
// we need to postpone that decision until the first test result.
//
// This works but is NOT USED, we prefer to have the same experience of not showing passed tests in hotReload mode as in normal mode.
// Func<bool> showPassed = () => _runtimeFeature.IsHotReloadEnabled;
Func<bool> showPassed = () => false;
bool outputOption = _commandLineOptions.TryGetOptionArgumentList(TerminalTestReporterCommandLineOptionsProvider.OutputOption, out string[]? arguments);
if (outputOption && arguments?.Length > 0 && TerminalTestReporterCommandLineOptionsProvider.OutputOptionDetailedArgument.Equals(arguments[0], StringComparison.OrdinalIgnoreCase))
{
showPassed = true;
showPassed = () => true;
}

Func<bool?> shouldShowProgress = noProgress
Expand Down Expand Up @@ -270,6 +275,9 @@ public virtual async Task DisplayBannerAsync(string? bannerMessage)
}
}

public async Task DisplayBeforeHotReloadSessionStartAsync()
=> await DisplayBeforeSessionStartAsync();

public async Task DisplayBeforeSessionStartAsync()
{
RoslynDebug.Assert(_terminalTestReporter is not null);
Expand All @@ -284,15 +292,30 @@ public async Task DisplayBeforeSessionStartAsync()
}
}

public async Task DisplayAfterHotReloadSessionEndAsync()
=> await DisplayAfterSessionEndRunInternalAsync();

public async Task DisplayAfterSessionEndRunAsync()
{
RoslynDebug.Assert(_terminalTestReporter is not null);

if (_isVSTestMode || _isListTests || _isServerMode)
{
return;
}

// Do NOT check and store the value in the constructor
// it won't be populated yet, so you will always see false.
if (_runtimeFeature.IsHotReloadEnabled)
{
return;
}

await DisplayAfterSessionEndRunInternalAsync();
}

private async Task DisplayAfterSessionEndRunInternalAsync()
{
RoslynDebug.Assert(_terminalTestReporter is not null);

using (await _asyncMonitor.LockAsync(TimeoutHelper.DefaultHangTimeSpanTimeout))
{
if (!_firstCallTo_OnSessionStartingAsync)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void OutputFormattingIsCorrect()
var stringBuilderConsole = new StringBuilderConsole();
var terminalReporter = new TerminalTestReporter(stringBuilderConsole, new TerminalTestReporterOptions
{
ShowPassedTests = true,
ShowPassedTests = () => true,
UseAnsi = true,
ForceAnsi = true,

Expand Down