From 27b8768988d1d3ffa0c3c192f005cf2d4f458c68 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 11 Dec 2024 12:22:30 +0100 Subject: [PATCH] Display an error when '--maximum-failed-tests' is used with a framework not implementing the required capability --- .../AbortForMaxFailedTestsExtension.cs | 23 +++++++++++++++++-- .../Hosts/TestHostBuilder.cs | 1 + .../Resources/PlatformResources.resx | 5 +++- .../Resources/xlf/PlatformResources.cs.xlf | 5 ++++ .../Resources/xlf/PlatformResources.de.xlf | 5 ++++ .../Resources/xlf/PlatformResources.es.xlf | 5 ++++ .../Resources/xlf/PlatformResources.fr.xlf | 5 ++++ .../Resources/xlf/PlatformResources.it.xlf | 5 ++++ .../Resources/xlf/PlatformResources.ja.xlf | 5 ++++ .../Resources/xlf/PlatformResources.ko.xlf | 5 ++++ .../Resources/xlf/PlatformResources.pl.xlf | 5 ++++ .../Resources/xlf/PlatformResources.pt-BR.xlf | 5 ++++ .../Resources/xlf/PlatformResources.ru.xlf | 5 ++++ .../Resources/xlf/PlatformResources.tr.xlf | 5 ++++ .../xlf/PlatformResources.zh-Hans.xlf | 5 ++++ .../xlf/PlatformResources.zh-Hant.xlf | 5 ++++ 16 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/Extensions/AbortForMaxFailedTestsExtension.cs b/src/Platform/Microsoft.Testing.Platform/Extensions/AbortForMaxFailedTestsExtension.cs index 78e4999b3c..7814217e37 100644 --- a/src/Platform/Microsoft.Testing.Platform/Extensions/AbortForMaxFailedTestsExtension.cs +++ b/src/Platform/Microsoft.Testing.Platform/Extensions/AbortForMaxFailedTestsExtension.cs @@ -4,19 +4,22 @@ using Microsoft.Testing.Platform.Capabilities.TestFramework; using Microsoft.Testing.Platform.CommandLine; using Microsoft.Testing.Platform.Extensions.Messages; +using Microsoft.Testing.Platform.Extensions.OutputDevice; using Microsoft.Testing.Platform.Extensions.TestHost; using Microsoft.Testing.Platform.Helpers; using Microsoft.Testing.Platform.Messages; +using Microsoft.Testing.Platform.OutputDevice; using Microsoft.Testing.Platform.Resources; using Microsoft.Testing.Platform.Services; namespace Microsoft.Testing.Platform.Extensions; -internal sealed class AbortForMaxFailedTestsExtension : IDataConsumer +internal sealed class AbortForMaxFailedTestsExtension : IDataConsumer, IOutputDeviceDataProducer { private readonly int? _maxFailedTests; private readonly IGracefulStopTestExecutionCapability? _capability; private readonly IStopPoliciesService _policiesService; + private readonly IOutputDevice _outputDevice; private readonly ITestApplicationCancellationTokenSource _testApplicationCancellationTokenSource; private int _failCount; @@ -24,6 +27,7 @@ public AbortForMaxFailedTestsExtension( ICommandLineOptions commandLineOptions, IGracefulStopTestExecutionCapability? capability, IStopPoliciesService policiesService, + IOutputDevice outputDevice, ITestApplicationCancellationTokenSource testApplicationCancellationTokenSource) { if (commandLineOptions.TryGetOptionArgumentList(MaxFailedTestsCommandLineOptionsProvider.MaxFailedTestsOptionKey, out string[]? args) && @@ -35,6 +39,7 @@ public AbortForMaxFailedTestsExtension( _capability = capability; _policiesService = policiesService; + _outputDevice = outputDevice; _testApplicationCancellationTokenSource = testApplicationCancellationTokenSource; } @@ -53,7 +58,21 @@ public AbortForMaxFailedTestsExtension( public string Description { get; } = PlatformResources.AbortForMaxFailedTestsDescription; /// - public Task IsEnabledAsync() => Task.FromResult(_maxFailedTests.HasValue && _capability is not null); + public async Task IsEnabledAsync() + { + if (!_maxFailedTests.HasValue) + { + return false; + } + + if (_capability is null) + { + await _outputDevice.DisplayAsync(this, new ErrorMessageOutputDeviceData(PlatformResources.AbortForMaxFailedTestsCapabilityNotAvailable)); + return false; + } + + return true; + } public async Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationToken cancellationToken) { diff --git a/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs b/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs index b071f4fb9f..2f26c217eb 100644 --- a/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs +++ b/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs @@ -738,6 +738,7 @@ private async Task BuildTestFrameworkAsync(TestFrameworkBuilderD serviceProvider.GetCommandLineOptions(), serviceProvider.GetTestFrameworkCapabilities().GetCapability(), serviceProvider.GetRequiredService(), + serviceProvider.GetOutputDevice(), serviceProvider.GetTestApplicationCancellationTokenSource()); if (await abortForMaxFailedTestsExtension.IsEnabledAsync()) diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index 4047fa6895..65315ba89c 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -713,4 +713,7 @@ Takes one argument as string in the format <value>[h|m|s] where 'value' is Test session is aborting due to reaching failures ('{0}') specified by the '--maximum-failed-tests' option. {0} is the number of max failed tests. - + + The current test framework does not support '--maximum-failed-tests'. + + \ No newline at end of file diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf index 95c3be44f2..6d5d000373 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf index 5ad7e52816..2a73040b77 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf index 58c731750f..83a1b7170c 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf index 6529f58252..34a964eb48 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf index 15d86d4003..dd448a228b 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf index 18e1d555d3..8d0208e2d9 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf index c8b3cbeb40..7ef600f60d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf index 010f80b6d0..aaa08db3d5 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf index 6046c82389..8b14330adc 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf index 59ba762b05..9d9e3ad0ab 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf index bbaf34f0ff..e3c73463ee 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf index 1e6719edca..9ec537dbcf 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf index 5d8b20aad0..bd7454defd 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf @@ -2,6 +2,11 @@ + + The current test framework does not support '--maximum-failed-tests'. + The current test framework does not support '--maximum-failed-tests'. + + Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted. Extension used to support '--maximum-failed-tests'. When a given failures threshold is reached, the test run will be aborted.