Skip to content

Commit 283ef97

Browse files
[release/11.0.1xx-preview7] Source code updates from dotnet/sdk (#7974)
[release/11.0.1xx-preview7] Source code updates from dotnet/sdk - Merge branch 'release/11.0.1xx-preview7' into darc-release/11.0.1xx-preview7-a3373d76-1991-4b42-ad79-74588503adb8
1 parent ab4a9a5 commit 283ef97

38 files changed

Lines changed: 1337 additions & 63 deletions

‎src/sdk/src/Cli/Microsoft.DotNet.Cli.Definitions/CommandDefinitionStrings.resx‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,22 @@ To display a value, specify the corresponding command-line option without provid
13441344
<value>VERSION</value>
13451345
</data>
13461346
<data name="CmdMinimumExpectedTestsDescription" xml:space="preserve">
1347-
<value>Specifies the minimum number of tests that are expected to run.</value>
1347+
<value>Specifies the minimum number of tests that are expected to run across all test applications. Pass after '--' to apply per test application.</value>
1348+
</data>
1349+
<data name="CmdMaximumFailedTestsDescription" xml:space="preserve">
1350+
<value>Stops test execution when the specified number of failures is reached across all test applications. Pass after '--' to apply per test application when supported.</value>
1351+
</data>
1352+
<data name="CmdTimeoutDescription" xml:space="preserve">
1353+
<value>Stops test execution when the specified test execution time is reached across all test applications. Pass after '--' to apply per test application.</value>
1354+
</data>
1355+
<data name="CmdDurationName" xml:space="preserve">
1356+
<value>DURATION</value>
1357+
</data>
1358+
<data name="CmdTestPositiveIntegerRequired" xml:space="preserve">
1359+
<value>The value must be a positive integer.</value>
1360+
</data>
1361+
<data name="CmdTestInvalidTimeout" xml:space="preserve">
1362+
<value>The timeout must be a positive duration with an explicit unit suffix such as ms, s, m, h, or d (longer forms like 'seconds', 'minutes', 'hours', and 'days' are also accepted).</value>
13481363
</data>
13491364
<data name="Option_Output" xml:space="preserve">
13501365
<value>Location to place the generated output.</value>

‎src/sdk/src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Test/TestCommandDefinition.MicrosoftTestingPlatform.cs‎

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33

44
using System.Collections.ObjectModel;
55
using System.CommandLine;
6+
using System.CommandLine.Parsing;
7+
using System.Globalization;
8+
using System.Text.RegularExpressions;
69
using Microsoft.DotNet.Cli.CommandLine;
710
using Microsoft.DotNet.Cli.Help;
811

912
namespace Microsoft.DotNet.Cli.Commands.Test;
1013

1114
internal abstract partial class TestCommandDefinition
1215
{
13-
public sealed class MicrosoftTestingPlatform : TestCommandDefinition, ICustomHelp
16+
public sealed partial class MicrosoftTestingPlatform : TestCommandDefinition, ICustomHelp
1417
{
18+
private const long MaxSupportedTimeoutMilliseconds = 0xfffffffe;
19+
1520
public readonly Option<string> ProjectOrSolutionOption = new("--project")
1621
{
1722
Description = CommandDefinitionStrings.CmdProjectOrSolutionDescriptionFormat,
@@ -77,6 +82,21 @@ public sealed class MicrosoftTestingPlatform : TestCommandDefinition, ICustomHel
7782
HelpName = CommandDefinitionStrings.CmdNumberName
7883
};
7984

85+
public readonly Option<int?> MaximumFailedTestsOption = new("--maximum-failed-tests")
86+
{
87+
Description = CommandDefinitionStrings.CmdMaximumFailedTestsDescription,
88+
HelpName = CommandDefinitionStrings.CmdNumberName,
89+
Arity = ArgumentArity.ExactlyOne
90+
};
91+
92+
public readonly Option<TimeSpan?> TimeoutOption = new("--timeout")
93+
{
94+
Description = CommandDefinitionStrings.CmdTimeoutDescription,
95+
HelpName = CommandDefinitionStrings.CmdDurationName,
96+
Arity = ArgumentArity.ExactlyOne,
97+
CustomParser = ParseTimeout
98+
};
99+
80100
public readonly Option<IReadOnlyDictionary<string, string>> EnvOption = CommonOptions.CreateEnvOption();
81101

82102
public readonly Option<ReadOnlyDictionary<string, string>?> PropertiesOption = CommonOptions.CreatePropertyOption();
@@ -166,6 +186,9 @@ public sealed class MicrosoftTestingPlatform : TestCommandDefinition, ICustomHel
166186
public MicrosoftTestingPlatform()
167187
: base(CommandDefinitionStrings.DotnetTestCommandMTPDescription)
168188
{
189+
MinimumExpectedTestsOption.Validators.Add(ValidatePositiveInteger);
190+
MaximumFailedTestsOption.Validators.Add(ValidatePositiveInteger);
191+
169192
Options.Add(ProjectOrSolutionOption);
170193
Options.Add(SolutionOption);
171194
Options.Add(TestModulesFilterOption);
@@ -175,6 +198,8 @@ public MicrosoftTestingPlatform()
175198
Options.Add(DiagnosticOutputDirectoryOption);
176199
Options.Add(MaxParallelTestModulesOption);
177200
Options.Add(MinimumExpectedTestsOption);
201+
Options.Add(MaximumFailedTestsOption);
202+
Options.Add(TimeoutOption);
178203
Options.Add(EnvOption);
179204
Options.Add(PropertiesOption);
180205
Options.Add(ConfigurationOption);
@@ -183,6 +208,7 @@ public MicrosoftTestingPlatform()
183208
Options.Add(VerbosityOption);
184209
Options.Add(NoRestoreOption);
185210
Options.Add(NoBuildOption);
211+
NoLogoOption.Aliases.Add("--no-banner");
186212
Options.Add(NoLogoOption);
187213
Options.Add(NoDependenciesOption);
188214
Options.Add(ArtifactsPathOption);
@@ -200,5 +226,66 @@ public MicrosoftTestingPlatform()
200226

201227
public IEnumerable<Action<HelpContext>> CustomHelpLayout()
202228
=> CustomHelpLayoutProvider?.CustomHelpLayout() ?? [];
229+
230+
private static void ValidatePositiveInteger(OptionResult optionResult)
231+
{
232+
if (optionResult.Tokens.Count == 1 &&
233+
int.TryParse(optionResult.Tokens[0].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int value) &&
234+
value <= 0)
235+
{
236+
optionResult.AddError(CommandDefinitionStrings.CmdTestPositiveIntegerRequired);
237+
}
238+
}
239+
240+
private static TimeSpan? ParseTimeout(ArgumentResult argumentResult)
241+
{
242+
if (argumentResult.Tokens.Count != 1)
243+
{
244+
return null;
245+
}
246+
247+
string value = argumentResult.Tokens[0].Value;
248+
Match match = TimeoutPattern().Match(value);
249+
if (!match.Success ||
250+
!double.TryParse(match.Groups["value"].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out double number))
251+
{
252+
argumentResult.AddError(CommandDefinitionStrings.CmdTestInvalidTimeout);
253+
return null;
254+
}
255+
256+
string suffix = match.Groups["suffix"].Value;
257+
TimeSpan timeout;
258+
try
259+
{
260+
timeout = suffix.StartsWith("ms", StringComparison.OrdinalIgnoreCase) ||
261+
suffix.StartsWith("mil", StringComparison.OrdinalIgnoreCase)
262+
? TimeSpan.FromMilliseconds(number)
263+
: suffix.StartsWith("s", StringComparison.OrdinalIgnoreCase)
264+
? TimeSpan.FromSeconds(number)
265+
: suffix.StartsWith("m", StringComparison.OrdinalIgnoreCase)
266+
? TimeSpan.FromMinutes(number)
267+
: suffix.StartsWith("h", StringComparison.OrdinalIgnoreCase)
268+
? TimeSpan.FromHours(number)
269+
: TimeSpan.FromDays(number);
270+
}
271+
catch (Exception ex) when (ex is OverflowException or ArgumentException)
272+
{
273+
argumentResult.AddError(CommandDefinitionStrings.CmdTestInvalidTimeout);
274+
return null;
275+
}
276+
277+
if (timeout <= TimeSpan.Zero || timeout.TotalMilliseconds > MaxSupportedTimeoutMilliseconds)
278+
{
279+
argumentResult.AddError(CommandDefinitionStrings.CmdTestInvalidTimeout);
280+
return null;
281+
}
282+
283+
return timeout;
284+
}
285+
286+
[GeneratedRegex(
287+
@"^(?<value>\d+(?:\.\d+)?)(?:\s*(?<suffix>ms|mils?|milliseconds?|s|secs?|seconds?|m|mins?|minutes?|h|hours?|d|days?))$",
288+
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
289+
private static partial Regex TimeoutPattern();
203290
}
204291
}

‎src/sdk/src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.cs.xlf‎

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

‎src/sdk/src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.de.xlf‎

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

‎src/sdk/src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.es.xlf‎

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

0 commit comments

Comments
 (0)