Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.Testing.Platform.Logging;
using Microsoft.Testing.Platform.Messages;
using Microsoft.Testing.Platform.OutputDevice;
using Microsoft.Testing.Platform.OutputDevice.Terminal;
using Microsoft.Testing.Platform.Requests;
using Microsoft.Testing.Platform.ServerMode;
using Microsoft.Testing.Platform.Services;
Expand Down Expand Up @@ -195,6 +196,8 @@ public async Task<ITestHost> BuildAsync(
// Add the platform output device to the service provider for both modes.
serviceProvider.TryAddService(platformOutputDevice);

CommandLine.AddProvider(() => new TerminalTestReporterCommandLineOptionsProvider());
Comment thread
nohwnd marked this conversation as resolved.
Resolved

// Build the command line service - we need special treatment because is possible that an extension query it during the creation.
// Add Retry default argument commandlines
CommandLineHandler commandLineHandler = await ((CommandLineManager)CommandLine).BuildAsync(platformOutputDevice, loggingState.CommandLineParseResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal async Task<IPlatformOutputDevice> BuildAsync(ServiceProvider servicePro
loggingState.CommandLineParseResult.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey),
PlatformCommandLineProvider.GetMinimumExpectedTests(loggingState.CommandLineParseResult),
loggingState.FileLoggerProvider,
serviceProvider.GetClock());
serviceProvider.GetClock(),
loggingState.CommandLineParseResult);
}
}
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.CommandLine;
using Microsoft.Testing.Platform.Extensions;
using Microsoft.Testing.Platform.Extensions.CommandLine;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Resources;

namespace Microsoft.Testing.Platform.OutputDevice.Terminal;

internal sealed class TerminalTestReporterCommandLineOptionsProvider : ICommandLineOptionsProvider
{
public const string NoProgressOption = "no-progress";
public const string NoAnsiOption = "no-ansi";

/// <inheritdoc />
public string Uid { get; } = nameof(TerminalTestReporterCommandLineOptionsProvider);

/// <inheritdoc />
public string Version { get; } = AppVersion.DefaultSemVer;

/// <inheritdoc />
public string DisplayName { get; } = PlatformResources.TerminalTestReporterDisplayName;

/// <inheritdoc />
public string Description { get; } = PlatformResources.TerminalTestReporterDescription;

/// <inheritdoc />
public Task<bool> IsEnabledAsync() => Task.FromResult(true);

public IReadOnlyCollection<CommandLineOption> GetCommandLineOptions()
=>
[
new(NoProgressOption, PlatformResources.TerminalNoProgressOptionDescription, ArgumentArity.Zero, false),
new(NoAnsiOption, PlatformResources.TerminalNoAnsiOptionDescription, ArgumentArity.Zero, false)
];

public Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments)
=> ValidationResult.ValidTask;

public Task<ValidationResult> ValidateCommandLineOptionsAsync(ICommandLineOptions commandLineOptions)
=> // No problem found
ValidationResult.ValidTask;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using System.Text;

using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Extensions.OutputDevice;
using Microsoft.Testing.Platform.Extensions.TestHost;
Expand Down Expand Up @@ -57,7 +58,7 @@ internal partial class TerminalOutputDevice : IPlatformOutputDevice,
public TerminalOutputDevice(ITestApplicationCancellationTokenSource testApplicationCancellationTokenSource, IConsole console,
ITestApplicationModuleInfo testApplicationModuleInfo, ITestHostControllerInfo testHostControllerInfo, IAsyncMonitor asyncMonitor,
IRuntimeFeature runtimeFeature, IEnvironment environment, IProcessHandler process, IPlatformInformation platformInformation,
bool isVSTestMode, bool isListTests, bool isServerMode, int minimumExpectedTest, FileLoggerProvider? fileLoggerProvider, IClock clock)
bool isVSTestMode, bool isListTests, bool isServerMode, int minimumExpectedTest, FileLoggerProvider? fileLoggerProvider, IClock clock, CommandLineParseResult parseResult)
{
_testApplicationCancellationTokenSource = testApplicationCancellationTokenSource;
_testApplicationModuleInfo = testApplicationModuleInfo;
Expand Down Expand Up @@ -94,6 +95,21 @@ public TerminalOutputDevice(ITestApplicationCancellationTokenSource testApplicat
_bannerDisplayed = true;
}

bool noAnsi = parseResult.IsOptionSet(TerminalTestReporterCommandLineOptionsProvider.NoAnsiOption);
bool noProgress = parseResult.IsOptionSet(TerminalTestReporterCommandLineOptionsProvider.NoProgressOption);

Func<bool?> shouldShowProgress = noProgress
// User preference is to not show progress.
? () => false
// User preference is to allow showing progress, figure if we should actually show it based on whether or not we are a testhost controller.
//
// TestHost controller is not running any tests and it should not be writing progress.
//
// The test host controller info is not setup and populated until after this constructor, because it writes banner and then after it figures out if
// the runner is a testHost controller, so we would always have it as null if we capture it directly. Instead we need to check it via
// func.
: () => testHostControllerInfo.IsCurrentProcessTestHostController == null ? null : !testHostControllerInfo.IsCurrentProcessTestHostController;

// This is single exe run, don't show all the details of assemblies and their summaries
// and don't show passed tests.
bool verbose = false;
Expand All @@ -104,12 +120,8 @@ public TerminalOutputDevice(ITestApplicationCancellationTokenSource testApplicat
ShowAssemblyStartAndComplete = verbose,
ShowPassedTests = verbose,
MinimumExpectedTests = minimumExpectedTest,
UseAnsi = true,
// TestHost controller is not running any tests and it should not be writing progress.
// The test host controller info is not setup and populated until after this constructor, because it writes banner and then after it figures out if
// the runner is a testHost controller, so we would always have it as null if we capture it directly. Instead we need to check it via
// func.
ShowProgress = () => testHostControllerInfo.IsCurrentProcessTestHostController == null ? null : !testHostControllerInfo.IsCurrentProcessTestHostController,
UseAnsi = !noAnsi,
ShowProgress = shouldShowProgress,
});

_testApplicationCancellationTokenSource.CancellationToken.Register(() => _terminalTestReporter.StartCancelling());
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,16 @@ Read more about Microsoft Testing Platform telemetry: https://aka.ms/testingplat
<value>in</value>
<comment>in that is used in stack frame it is followed by file name</comment>
</data>
<data name="TerminalNoAnsiOptionDescription" xml:space="preserve">
<value>Disable outputting ANSI escape characters to screen.</value>
</data>
<data name="TerminalNoProgressOptionDescription" xml:space="preserve">
<value>Disable reporting progress to screen.</value>
</data>
<data name="TerminalTestReporterDescription" xml:space="preserve">
<value>Writes test results to terminal.</value>
</data>
<data name="TerminalTestReporterDisplayName" xml:space="preserve">
<value>Terminal test reporter</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,26 @@ Přečtěte si další informace o telemetrii Microsoft Testing Platform: https:
<target state="translated">Zprostředkovatel telemetrie je už nastavený.</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoAnsiOptionDescription">
<source>Disable outputting ANSI escape characters to screen.</source>
<target state="new">Disable outputting ANSI escape characters to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoProgressOptionDescription">
<source>Disable reporting progress to screen.</source>
<target state="new">Disable reporting progress to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDescription">
<source>Writes test results to terminal.</source>
<target state="new">Writes test results to terminal.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDisplayName">
<source>Terminal test reporter</source>
<target state="new">Terminal test reporter</target>
<note />
</trans-unit>
<trans-unit id="TestAdapterInvokerFactoryAlreadySetErrorMessage">
<source>An 'ITestFrameworkInvoker' factory is already set</source>
<target state="translated">Objekt pro vytváření ITestFrameworkInvoker je už nastavený.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,26 @@ Weitere Informationen zu Microsoft Testing Platform-Telemetriedaten: https://aka
<target state="translated">Der Telemetrieanbieter ist bereits festgelegt</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoAnsiOptionDescription">
<source>Disable outputting ANSI escape characters to screen.</source>
<target state="new">Disable outputting ANSI escape characters to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoProgressOptionDescription">
<source>Disable reporting progress to screen.</source>
<target state="new">Disable reporting progress to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDescription">
<source>Writes test results to terminal.</source>
<target state="new">Writes test results to terminal.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDisplayName">
<source>Terminal test reporter</source>
<target state="new">Terminal test reporter</target>
<note />
</trans-unit>
<trans-unit id="TestAdapterInvokerFactoryAlreadySetErrorMessage">
<source>An 'ITestFrameworkInvoker' factory is already set</source>
<target state="translated">Eine "ITestFrameworkInvoker"-Factory ist bereits festgelegt</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,26 @@ Más información sobre la telemetría de la Plataforma de pruebas de Microsoft:
<target state="translated">El proveedor de telemetría ya está establecido</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoAnsiOptionDescription">
<source>Disable outputting ANSI escape characters to screen.</source>
<target state="new">Disable outputting ANSI escape characters to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoProgressOptionDescription">
<source>Disable reporting progress to screen.</source>
<target state="new">Disable reporting progress to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDescription">
<source>Writes test results to terminal.</source>
<target state="new">Writes test results to terminal.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDisplayName">
<source>Terminal test reporter</source>
<target state="new">Terminal test reporter</target>
<note />
</trans-unit>
<trans-unit id="TestAdapterInvokerFactoryAlreadySetErrorMessage">
<source>An 'ITestFrameworkInvoker' factory is already set</source>
<target state="translated">Ya se ha establecido una fábrica "ITestFrameworkInvoker"</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,26 @@ En savoir plus sur la télémétrie de la plateforme de tests Microsoft : https:
<target state="translated">Le fournisseur de télémétrie est déjà défini</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoAnsiOptionDescription">
<source>Disable outputting ANSI escape characters to screen.</source>
<target state="new">Disable outputting ANSI escape characters to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoProgressOptionDescription">
<source>Disable reporting progress to screen.</source>
<target state="new">Disable reporting progress to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDescription">
<source>Writes test results to terminal.</source>
<target state="new">Writes test results to terminal.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDisplayName">
<source>Terminal test reporter</source>
<target state="new">Terminal test reporter</target>
<note />
</trans-unit>
<trans-unit id="TestAdapterInvokerFactoryAlreadySetErrorMessage">
<source>An 'ITestFrameworkInvoker' factory is already set</source>
<target state="translated">Désolé, une fabrique « ITestFrameworkInvoker » est déjà définie</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,26 @@ Altre informazioni sulla telemetria della piattaforma di test Microsoft: https:/
<target state="translated">Il provider di telemetria è già impostato</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoAnsiOptionDescription">
<source>Disable outputting ANSI escape characters to screen.</source>
<target state="new">Disable outputting ANSI escape characters to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoProgressOptionDescription">
<source>Disable reporting progress to screen.</source>
<target state="new">Disable reporting progress to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDescription">
<source>Writes test results to terminal.</source>
<target state="new">Writes test results to terminal.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDisplayName">
<source>Terminal test reporter</source>
<target state="new">Terminal test reporter</target>
<note />
</trans-unit>
<trans-unit id="TestAdapterInvokerFactoryAlreadySetErrorMessage">
<source>An 'ITestFrameworkInvoker' factory is already set</source>
<target state="translated">Una factory 'ITestFrameworkInvoker' è già impostata</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,26 @@ Microsoft Testing Platform テレメトリの詳細: https://aka.ms/testingplatf
<target state="translated">テレメトリ プロバイダーは既に設定されています</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoAnsiOptionDescription">
<source>Disable outputting ANSI escape characters to screen.</source>
<target state="new">Disable outputting ANSI escape characters to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoProgressOptionDescription">
<source>Disable reporting progress to screen.</source>
<target state="new">Disable reporting progress to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDescription">
<source>Writes test results to terminal.</source>
<target state="new">Writes test results to terminal.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDisplayName">
<source>Terminal test reporter</source>
<target state="new">Terminal test reporter</target>
<note />
</trans-unit>
<trans-unit id="TestAdapterInvokerFactoryAlreadySetErrorMessage">
<source>An 'ITestFrameworkInvoker' factory is already set</source>
<target state="translated">'ITestFrameworkInvoker' ファクトリは既に設定されています</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,26 @@ Microsoft 테스트 플랫폼 원격 분석에 대해 자세히 알아보기: ht
<target state="translated">원격 분석 공급자가 이미 설정되어 있습니다.</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoAnsiOptionDescription">
<source>Disable outputting ANSI escape characters to screen.</source>
<target state="new">Disable outputting ANSI escape characters to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalNoProgressOptionDescription">
<source>Disable reporting progress to screen.</source>
<target state="new">Disable reporting progress to screen.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDescription">
<source>Writes test results to terminal.</source>
<target state="new">Writes test results to terminal.</target>
<note />
</trans-unit>
<trans-unit id="TerminalTestReporterDisplayName">
<source>Terminal test reporter</source>
<target state="new">Terminal test reporter</target>
<note />
</trans-unit>
<trans-unit id="TestAdapterInvokerFactoryAlreadySetErrorMessage">
<source>An 'ITestFrameworkInvoker' factory is already set</source>
<target state="translated">'ITestFrameworkInvoker' 팩터리가 이미 설정됨</target>
Expand Down
Loading