Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,45 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Services;
Comment thread
Evangelink marked this conversation as resolved.
Resolved

namespace Microsoft.Testing.Platform.OutputDevice;

internal static class OutputDeviceBannerHelper
{
#pragma warning disable SA1310 // Field names should not contain underscore
internal const string TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER = nameof(TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER);
#pragma warning restore SA1310 // Field names should not contain underscore

internal static string BuildBannerText(IPlatformInformation platformInformation, IRuntimeFeature runtimeFeature, string? longArchitecture, string? runtimeFramework)
{
StringBuilder stringBuilder = new();
stringBuilder.Append(platformInformation.Name);

if (platformInformation.Version is { } version)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $" v{version}");
if (platformInformation.CommitHash is { } commitHash)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $"+{commitHash[..10]}");
Comment thread
Evangelink marked this conversation as resolved.
Resolved
}
}

if (platformInformation.BuildDate is { } buildDate)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $" (UTC {buildDate.UtcDateTime:d})");
}

if (runtimeFeature.IsDynamicCodeSupported)
{
stringBuilder.Append(" [");
stringBuilder.Append(longArchitecture);
stringBuilder.Append(" - ");
stringBuilder.Append(runtimeFramework);
stringBuilder.Append(']');
}

return stringBuilder.ToString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ internal abstract class SimplifiedConsoleOutputDeviceBase : IPlatformOutputDevic
ITestSessionLifetimeHandler,
IAsyncInitializableExtension
{
#pragma warning disable SA1310 // Field names should not contain underscore
private const string TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER = nameof(TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER);
#pragma warning restore SA1310 // Field names should not contain underscore

private readonly IConsole _console;
private readonly IAsyncMonitor _asyncMonitor;
private readonly IRuntimeFeature _runtimeFeature;
Expand Down Expand Up @@ -74,7 +70,7 @@ protected SimplifiedConsoleOutputDeviceBase(

_assemblyName = testApplicationModuleInfo.GetDisplayName();

if (environment.GetEnvironmentVariable(TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER) is not null)
if (environment.GetEnvironmentVariable(OutputDeviceBannerHelper.TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER) is not null)
{
_bannerDisplayed = true;
}
Expand Down Expand Up @@ -127,7 +123,7 @@ public async Task DisplayBannerAsync(string? bannerMessage, CancellationToken ca
}

// skip the banner for the children processes
_environment.SetEnvironmentVariable(TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER, "1");
_environment.SetEnvironmentVariable(OutputDeviceBannerHelper.TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER, "1");

_bannerDisplayed = true;

Expand All @@ -137,33 +133,7 @@ public async Task DisplayBannerAsync(string? bannerMessage, CancellationToken ca
return;
}

StringBuilder stringBuilder = new();
stringBuilder.Append(_platformInformation.Name);

if (_platformInformation.Version is { } version)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $" v{version}");
if (_platformInformation.CommitHash is { } commitHash)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $"+{commitHash[..10]}");
}
}

if (_platformInformation.BuildDate is { } buildDate)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $" (UTC {buildDate.UtcDateTime:d})");
}

if (_runtimeFeature.IsDynamicCodeSupported)
{
stringBuilder.Append(" [");
stringBuilder.Append(_longArchitecture);
stringBuilder.Append(" - ");
stringBuilder.Append(_runtimeFramework);
stringBuilder.Append(']');
}

ConsoleLog(stringBuilder.ToString());
ConsoleLog(OutputDeviceBannerHelper.BuildBannerText(_platformInformation, _runtimeFeature, _longArchitecture, _runtimeFramework));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ internal sealed partial class TerminalOutputDevice : IHotReloadPlatformOutputDev
IAsyncInitializableExtension
{
#pragma warning disable SA1310 // Field names should not contain underscore
private const string TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER = nameof(TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER);

// Opt-in knobs (env vars only) for the silence-driven heartbeat renderer used in non-cursor modes.
private const string MTP_PROGRESS_SILENCE_SECONDS = nameof(MTP_PROGRESS_SILENCE_SECONDS);
private const string MTP_PROGRESS_SLOW_TEST_SECONDS = nameof(MTP_PROGRESS_SLOW_TEST_SECONDS);
Expand Down Expand Up @@ -110,7 +108,7 @@ public TerminalOutputDevice(

_assemblyName = testApplicationModuleInfo.GetDisplayName();

if (environment.GetEnvironmentVariable(TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER) is not null)
if (environment.GetEnvironmentVariable(OutputDeviceBannerHelper.TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER) is not null)
{
_bannerDisplayed = true;
}
Expand Down Expand Up @@ -371,7 +369,7 @@ public async Task DisplayBannerAsync(string? bannerMessage, CancellationToken ca
// The env var propagates to any child test host the controller spawns so they also
// stay quiet — important because the JSON document must be the sole stdout content.
_bannerDisplayed = true;
_environment.SetEnvironmentVariable(TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER, "1");
_environment.SetEnvironmentVariable(OutputDeviceBannerHelper.TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER, "1");
return;
}

Expand All @@ -380,7 +378,7 @@ public async Task DisplayBannerAsync(string? bannerMessage, CancellationToken ca
if (!_bannerDisplayed && !_isServerMode)
{
// skip the banner for the children processes
_environment.SetEnvironmentVariable(TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER, "1");
_environment.SetEnvironmentVariable(OutputDeviceBannerHelper.TESTINGPLATFORM_CONSOLEOUTPUTDEVICE_SKIP_BANNER, "1");

_bannerDisplayed = true;

Expand All @@ -390,33 +388,7 @@ public async Task DisplayBannerAsync(string? bannerMessage, CancellationToken ca
}
else
{
StringBuilder stringBuilder = new();
stringBuilder.Append(_platformInformation.Name);

if (_platformInformation.Version is { } version)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $" v{version}");
if (_platformInformation.CommitHash is { } commitHash)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $"+{commitHash[..10]}");
}
}

if (_platformInformation.BuildDate is { } buildDate)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $" (UTC {buildDate.UtcDateTime:d})");
}

if (_runtimeFeature.IsDynamicCodeSupported)
{
stringBuilder.Append(" [");
stringBuilder.Append(_longArchitecture);
stringBuilder.Append(" - ");
stringBuilder.Append(_runtimeFramework);
stringBuilder.Append(']');
}

_terminalTestReporter.WriteMessage(stringBuilder.ToString());
_terminalTestReporter.WriteMessage(OutputDeviceBannerHelper.BuildBannerText(_platformInformation, _runtimeFeature, _longArchitecture, _runtimeFramework));
Comment thread
Evangelink marked this conversation as resolved.
Resolved
}
}

Expand Down
Loading