Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,10 @@ public Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption com
return ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, PlatformResources.PlatformCommandLineExitOnProcessExitSingleArgument, ExitOnProcessExitOptionKey));
}

if (commandOption.Name == TimeoutOptionKey)
if (commandOption.Name == TimeoutOptionKey
&& !TryParseTimeoutArgument(arguments[0], out _))
{
string arg = arguments[0];
int size = arg.Length;
if ((char.ToLowerInvariant(arg[size - 1]) != 'h' && char.ToLowerInvariant(arg[size - 1]) != 'm' && char.ToLowerInvariant(arg[size - 1]) != 's') || !float.TryParse(arg[..(size - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float _))
{
return ValidationResult.InvalidTask(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage);
}
return ValidationResult.InvalidTask(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage);
}

if (commandOption.Name == ConfigFileOptionKey)
Expand Down Expand Up @@ -179,6 +175,48 @@ private static Task<ValidationResult> IsMinimumExpectedTestsOptionValidAsync(Com
? ValidationResult.InvalidTask(PlatformResources.PlatformCommandLineMinimumExpectedTestsOptionSingleArgument)
: ValidationResult.ValidTask;

internal static bool TryParseTimeoutArgument(string arg, out TimeSpan timeout)
{
timeout = TimeSpan.Zero;

// We need at least one digit plus a unit suffix (e.g. "1s").
if (arg is null || arg.Length < 2)
{
return false;
}

char unit = char.ToLowerInvariant(arg[arg.Length - 1]);
if (unit is not 'h' and not 'm' and not 's')
{
return false;
}

if (!float.TryParse(arg[..(arg.Length - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float value)
|| float.IsNaN(value)
|| float.IsInfinity(value)
|| value < 0)
{
return false;
}

try
{
timeout = unit switch
{
'h' => TimeSpan.FromHours(value),
'm' => TimeSpan.FromMinutes(value),
's' => TimeSpan.FromSeconds(value),
_ => throw ApplicationStateGuard.Unreachable(),
};
}
catch (OverflowException)
{
return false;
}

return true;
}

public Task<ValidationResult> ValidateCommandLineOptionsAsync(ICommandLineOptions commandLineOptions)
{
if (!commandLineOptions.IsOptionSet(DiagnosticOptionKey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,11 @@ private async Task<BuildContext> SetupCommonServicesAsync(
if (commandLineOptions.IsOptionSet(PlatformCommandLineProvider.TimeoutOptionKey)
&& commandLineOptions.TryGetOptionArgumentList(PlatformCommandLineProvider.TimeoutOptionKey, out string[]? args))
{
string arg = args[0];
int size = arg.Length;
if (!float.TryParse(arg[..(size - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float value))
if (!PlatformCommandLineProvider.TryParseTimeoutArgument(args[0], out TimeSpan timeout))
{
throw ApplicationStateGuard.Unreachable();
}

TimeSpan timeout = char.ToLowerInvariant(arg[size - 1]) switch
{
'h' => TimeSpan.FromHours(value),
'm' => TimeSpan.FromMinutes(value),
's' => TimeSpan.FromSeconds(value),
_ => throw ApplicationStateGuard.Unreachable(),
};

context.TestApplicationCancellationTokenSource.CancelAfter(timeout);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ Valid values are 'All', 'Failed', 'None'. Default is 'All'.</value>
<value>--show-stdout and --show-stderr expect a single parameter with value 'All', 'Failed', or 'None'.</value>
</data>
<data name="PlatformCommandLineTimeoutArgumentErrorMessage" xml:space="preserve">
<value>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</value>
<value>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</value>
</data>
<data name="PlatformCommandLineTimeoutOptionDescription" xml:space="preserve">
<value>A global test execution timeout.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ Výchozí hodnota je TestResults v adresáři, který obsahuje testovací aplika
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">Možnost timeout by měla mít jeden argument jako řetězec ve formátu &lt;value&gt;[h|m|s], kde value je hodnota datového typu float.</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">Možnost timeout by měla mít jeden argument jako řetězec ve formátu &lt;value&gt;[h|m|s], kde value je hodnota datového typu float.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ Der Standardwert ist "TestResults" im Verzeichnis, das die Testanwendung enthäl
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">Die Option "timeout" muss ein Argument als Zeichenfolge im Format &lt;value&gt;[h|m|s] aufweisen, wobei "value" auf "float" festgelegt ist.</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">Die Option "timeout" muss ein Argument als Zeichenfolge im Format &lt;value&gt;[h|m|s] aufweisen, wobei "value" auf "float" festgelegt ist.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ El valor predeterminado es TestResults en el directorio que contiene la aplicaci
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">La opción 'timeout' debe tener un argumento como cadena con el formato &lt;value&gt;[h|m|s] donde 'value' es float</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">La opción 'timeout' debe tener un argumento como cadena con el formato &lt;value&gt;[h|m|s] donde 'value' es float</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ La valeur par défaut est TestResults dans le répertoire qui contient l’appli
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">L’option « timeout » doit avoir un argument sous forme de chaîne au format &lt;value&gt;[h|m|s] où « value » est float</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">L’option « timeout » doit avoir un argument sous forme de chaîne au format &lt;value&gt;[h|m|s] où « value » est float</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ L’impostazione predefinita è TestResults nella directory che contiene l'appli
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">L'opzione 'timeout' deve contenere un argomento come stringa nel formato &lt;value&gt;[h|m|s] dove 'value' è float</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">L'opzione 'timeout' deve contenere un argomento come stringa nel formato &lt;value&gt;[h|m|s] dove 'value' è float</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ The default is TestResults in the directory that contains the test application.<
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">'timeout' オプションには、1 つの引数を文字列として &lt;value&gt;[h|m|s] の形式で指定する必要があります。この場合、'value' は float です</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">'timeout' オプションには、1 つの引数を文字列として &lt;value&gt;[h|m|s] の形式で指定する必要があります。この場合、'value' は float です</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ The default is TestResults in the directory that contains the test application.<
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">'timeout' 옵션에는 'value'가 float인 &lt;value&gt;[h|m|s] 형식의 문자열로 인수가 하나 있어야 합니다.</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">'timeout' 옵션에는 'value'가 float인 &lt;value&gt;[h|m|s] 형식의 문자열로 인수가 하나 있어야 합니다.</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ Wartość domyślna to TestResults w katalogu zawierającym aplikację testową.
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">Opcja „timeout” powinna mieć jeden argument jako ciąg w formacie &lt;value&gt;[h|m|s], gdzie element „value” ma wartość zmiennoprzecinkową</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">Opcja „timeout” powinna mieć jeden argument jako ciąg w formacie &lt;value&gt;[h|m|s], gdzie element „value” ma wartość zmiennoprzecinkową</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ O padrão é TestResults no diretório que contém o aplicativo de teste.</targe
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">A opção 'timeout' deve ter um argumento como cadeia de caracteres no formato &lt;value&gt;[h|m|s] onde 'value' é float</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">A opção 'timeout' deve ter um argumento como cadeia de caracteres no formato &lt;value&gt;[h|m|s] onde 'value' é float</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ The default is TestResults in the directory that contains the test application.<
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">Параметр "timeout" должен иметь один аргумент в виде строки в формате &lt;value&gt;[h|m|s], где "value" — число с плавающей точкой</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">Параметр "timeout" должен иметь один аргумент в виде строки в формате &lt;value&gt;[h|m|s], где "value" — число с плавающей точкой</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ Varsayılan değer, test uygulamasını içeren dizindeki TestResults'dır.</tar
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">'timeout' seçeneği, 'value' değerinin kayan olduğu &lt;value&gt;[h|m|s] biçiminde dize olarak bir bağımsız değişkene sahip olmalıdır</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">'timeout' seçeneği, 'value' değerinin kayan olduğu &lt;value&gt;[h|m|s] biçiminde dize olarak bir bağımsız değişkene sahip olmalıdır</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ The default is TestResults in the directory that contains the test application.<
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">"timeout" 选项应有一个字符串形式的参数,格式为 &lt;value&gt;[h|m|s],其中 "value" 为浮点型</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">"timeout" 选项应有一个字符串形式的参数,格式为 &lt;value&gt;[h|m|s],其中 "value" 为浮点型</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ The default is TestResults in the directory that contains the test application.<
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutArgumentErrorMessage">
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is float</source>
<target state="translated">'timeout' 選項應該有一個引數作為字串,格式為 &lt;value&gt;[h|m|s],其中 'value' 為 float</target>
<source>'timeout' option should have one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration</source>
<target state="needs-review-translation">'timeout' 選項應該有一個引數作為字串,格式為 &lt;value&gt;[h|m|s],其中 'value' 為 float</target>
<note />
</trans-unit>
<trans-unit id="PlatformCommandLineTimeoutOptionDescription">
Expand Down
Loading
Loading