Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -127,7 +127,11 @@ public Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption com
{
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 _))
if ((char.ToLowerInvariant(arg[size - 1]) != 'h' && char.ToLowerInvariant(arg[size - 1]) != 'm' && char.ToLowerInvariant(arg[size - 1]) != 's')
Comment thread
Evangelink marked this conversation as resolved.
Resolved
|| !float.TryParse(arg[..(size - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float value)
|| float.IsNaN(value)
|| float.IsInfinity(value)
|| value < 0)
{
return ValidationResult.InvalidTask(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage);
Comment thread
Evangelink marked this conversation as resolved.
Resolved
}
Comment thread
Evangelink marked this conversation as resolved.
Resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public async Task TimeoutWithInvalidArg_WithInvalidFormat_OutputInvalidMessage(s
testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float");
}

[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
public async Task TimeoutWithInvalidArg_WithNegativeValue_OutputInvalidMessage(string tfm)
{
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout -1s", cancellationToken: TestContext.CancellationToken);

testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine);
testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float");
}

[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
public async Task TimeoutWithValidArg_WithTestTimeOut_OutputContainsCancelingMessage(string tfm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ public async Task IsValid_If_Timeout_Has_CorrectFormat_InvariantCulture(string t
[DataRow("invalid")]
[DataRow("1.5")] // Missing unit
[DataRow("abc.5s")]
[DataRow("-1s")]
[DataRow("-0.5m")]
Comment thread
Evangelink marked this conversation as resolved.
Resolved
public async Task IsInvalid_If_Timeout_Has_IncorrectFormat(string timeout)
Comment thread
Evangelink marked this conversation as resolved.
Resolved
{
var provider = new PlatformCommandLineProvider();
Expand Down
Loading