|
3 | 3 |
|
4 | 4 | using System.Globalization;
|
5 | 5 |
|
| 6 | +using Microsoft.Testing.Platform.Capabilities.TestFramework; |
6 | 7 | using Microsoft.Testing.Platform.Extensions;
|
7 | 8 | using Microsoft.Testing.Platform.Extensions.CommandLine;
|
8 | 9 | using Microsoft.Testing.Platform.Helpers;
|
9 | 10 | using Microsoft.Testing.Platform.Resources;
|
| 11 | +using Microsoft.Testing.Platform.Services; |
10 | 12 |
|
11 | 13 | namespace Microsoft.Testing.Platform.CommandLine;
|
12 | 14 |
|
13 |
| -internal sealed class MaxFailedTestsCommandLineOptionsProvider(IExtension extension) : ICommandLineOptionsProvider |
| 15 | +internal sealed class MaxFailedTestsCommandLineOptionsProvider(IExtension extension, IServiceProvider serviceProvider) : ICommandLineOptionsProvider |
14 | 16 | {
|
15 | 17 | internal const string MaxFailedTestsOptionKey = "maximum-failed-tests";
|
16 | 18 |
|
@@ -44,10 +46,15 @@ public Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption com
|
44 | 46 | // The idea is that we stop the execution when we *reach* the max failed tests, not when *exceed*.
|
45 | 47 | // So the value 1 means, stop execution on the first failure.
|
46 | 48 | return int.TryParse(arg, out int maxFailedTestsResult) && maxFailedTestsResult > 0
|
47 |
| - ? ValidationResult.ValidTask |
| 49 | + ? ValidateCapabilityAsync() |
48 | 50 | : ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, PlatformResources.MaxFailedTestsMustBePositive, arg));
|
49 | 51 | }
|
50 | 52 |
|
51 | 53 | throw ApplicationStateGuard.Unreachable();
|
52 | 54 | }
|
| 55 | + |
| 56 | + private Task<ValidationResult> ValidateCapabilityAsync() |
| 57 | + => serviceProvider.GetTestFrameworkCapabilities().Capabilities.OfType<IGracefulStopTestExecutionCapability>().Any() |
| 58 | + ? ValidationResult.ValidTask |
| 59 | + : ValidationResult.InvalidTask(PlatformResources.AbortForMaxFailedTestsCapabilityNotAvailable); |
53 | 60 | }
|
0 commit comments