Skip to content

Commit ec71743

Browse files
Youssef1313Copilot
andauthored
Handle --minimum-expected-tests (#50527)
Co-authored-by: Copilot <[email protected]>
1 parent e464689 commit ec71743

26 files changed

+285
-2
lines changed

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,4 +2645,7 @@ Proceed?</value>
26452645
<data name="PackCmdVersion" xml:space="preserve">
26462646
<value>VERSION</value>
26472647
</data>
2648+
<data name="CmdMinimumExpectedTestsDescription" xml:space="preserve">
2649+
<value>Specifies the minimum number of tests that are expected to run.</value>
2650+
</data>
26482651
</root>

src/Cli/dotnet/Commands/Test/ExitCode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ internal static class ExitCode
1414
public const int Success = 0;
1515
public const int GenericFailure = 1;
1616
public const int ZeroTests = 8;
17+
public const int MinimumExpectedTestsPolicyViolation = 9;
1718
}

src/Cli/dotnet/Commands/Test/Terminal/TerminalTestReporter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ internal event EventHandler OnProgressStopUpdate
6262
private bool? _shouldShowPassedTests;
6363

6464
public bool HasHandshakeFailure => _handshakeFailuresCount > 0;
65+
public int TotalTests => _assemblies.Values.Sum(a => a.TotalTests);
6566

6667
// Specifying no timeout, the regex is linear. And the timeout does not measure the regex only, but measures also any
6768
// thread suspends, so the regex gets blamed incorrectly.

src/Cli/dotnet/Commands/Test/TestCommandParser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ private static Command GetTestingPlatformCliCommand()
237237
command.Options.Add(TestingPlatformOptions.ConfigFileOption);
238238
command.Options.Add(TestingPlatformOptions.DiagnosticOutputDirectoryOption);
239239
command.Options.Add(TestingPlatformOptions.MaxParallelTestModulesOption);
240+
command.Options.Add(TestingPlatformOptions.MinimumExpectedTestsOption);
240241
command.Options.Add(CommonOptions.ArchitectureOption);
241242
command.Options.Add(CommonOptions.PropertiesOption);
242243
command.Options.Add(TestingPlatformOptions.ConfigurationOption);

src/Cli/dotnet/Commands/Test/TestingPlatformCommand.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,18 @@ private int RunInternal(ParseResult parseResult)
8080
}
8181

8282
_actionQueue.EnqueueCompleted();
83-
var exitCode = _actionQueue.WaitAllActions();
8483
// Don't inline exitCode variable. We want to always call WaitAllActions first.
85-
return _eventHandlers.HasHandshakeFailure ? ExitCode.GenericFailure : exitCode;
84+
var exitCode = _actionQueue.WaitAllActions();
85+
exitCode = _eventHandlers.HasHandshakeFailure ? ExitCode.GenericFailure : exitCode;
86+
if (exitCode == ExitCode.Success &&
87+
parseResult.HasOption(TestingPlatformOptions.MinimumExpectedTestsOption) &&
88+
parseResult.GetValue(TestingPlatformOptions.MinimumExpectedTestsOption) is { } minimumExpectedTests &&
89+
_output.TotalTests < minimumExpectedTests)
90+
{
91+
exitCode = ExitCode.MinimumExpectedTestsPolicyViolation;
92+
}
93+
94+
return exitCode;
8695
}
8796

8897
private void PrepareEnvironment(ParseResult parseResult, out TestOptions testOptions, out int degreeOfParallelism)
@@ -142,6 +151,7 @@ private void InitializeOutput(int degreeOfParallelism, ParseResult parseResult,
142151
UseCIAnsi = inCI,
143152
ShowAssembly = true,
144153
ShowAssemblyStartAndComplete = true,
154+
MinimumExpectedTests = parseResult.GetValue(TestingPlatformOptions.MinimumExpectedTestsOption),
145155
});
146156

147157
_output.TestExecutionStarted(DateTimeOffset.Now, degreeOfParallelism, _isDiscovery, isHelp, _isRetry);

src/Cli/dotnet/Commands/Test/TestingPlatformOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ internal static class TestingPlatformOptions
6262
HelpName = CliCommandStrings.CmdNumberName
6363
};
6464

65+
public static readonly Option<int> MinimumExpectedTestsOption = new("--minimum-expected-tests")
66+
{
67+
Description = CliCommandStrings.CmdMinimumExpectedTestsDescription,
68+
HelpName = CliCommandStrings.CmdNumberName
69+
};
70+
6571
public static readonly Option<string> ConfigurationOption = CommonOptions.ConfigurationOption(CliCommandStrings.TestConfigurationOptionDescription);
6672

6773
public static readonly Option<string> FrameworkOption = CommonOptions.FrameworkOption(CliCommandStrings.TestFrameworkOptionDescription);

src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)