-
Notifications
You must be signed in to change notification settings - Fork 290
Fix MTP timeout parsing to use invariant culture instead of current culture #5705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
7a98fca
fb65280
3437087
c1d16a6
624ef07
58051d2
6648b09
ea8f52a
e69cb8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,4 +181,80 @@ | |
| Assert.IsFalse(validateOptionsResult.IsValid); | ||
| Assert.IsTrue(validateOptionsResult.ErrorMessage.StartsWith($"Invalid PID '{pid}'", StringComparison.OrdinalIgnoreCase)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("1.5s")] | ||
| [DataRow("2.0m")] | ||
| [DataRow("0.5h")] | ||
| [DataRow("10s")] | ||
| [DataRow("30m")] | ||
| [DataRow("1h")] | ||
| public async Task IsValid_If_Timeout_Has_CorrectFormat_InvariantCulture(string timeout) | ||
| { | ||
| var provider = new PlatformCommandLineProvider(); | ||
| CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == PlatformCommandLineProvider.TimeoutOptionKey); | ||
|
|
||
| // Save current culture | ||
| CultureInfo originalCulture = CultureInfo.CurrentCulture; | ||
| try | ||
| { | ||
| // Test with various cultures to ensure invariant parsing works | ||
| foreach (string cultureName in new[] { "en-US", "de-DE", "fr-FR" }) | ||
| { | ||
| CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(cultureName); | ||
| ValidationResult validateOptionsResult = await provider.ValidateOptionArgumentsAsync(option, [timeout]).ConfigureAwait(false); | ||
| Assert.IsTrue(validateOptionsResult.IsValid, $"Failed with culture {cultureName} and timeout {timeout}"); | ||
| Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); | ||
| } | ||
| } | ||
| finally | ||
| { | ||
| // Restore original culture | ||
| CultureInfo.CurrentCulture = originalCulture; | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("1,5s")] // German decimal separator | ||
| [DataRow("invalid")] | ||
| [DataRow("1.5")] // Missing unit | ||
|
Check failure on line 220 in test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs
|
||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [DataRow("abc.5s")] | ||
| public async Task IsInvalid_If_Timeout_Has_IncorrectFormat(string timeout) | ||
| { | ||
| var provider = new PlatformCommandLineProvider(); | ||
| CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == PlatformCommandLineProvider.TimeoutOptionKey); | ||
|
|
||
| ValidationResult validateOptionsResult = await provider.ValidateOptionArgumentsAsync(option, [timeout]).ConfigureAwait(false); | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Assert.IsFalse(validateOptionsResult.IsValid); | ||
| Assert.AreEqual(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage, validateOptionsResult.ErrorMessage); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Timeout_Parsing_Uses_InvariantCulture_NotCurrentCulture() | ||
| { | ||
| var provider = new PlatformCommandLineProvider(); | ||
| CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == PlatformCommandLineProvider.TimeoutOptionKey); | ||
|
|
||
| // Save current culture | ||
| CultureInfo originalCulture = CultureInfo.CurrentCulture; | ||
|
|
||
|
Check failure on line 240 in test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs
|
||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try | ||
| { | ||
| // Set culture to German where decimal separator is comma | ||
| CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE"); | ||
|
|
||
|
Check failure on line 245 in test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs
|
||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // This should work because we use invariant culture (period as decimal separator) | ||
| ValidationResult validResult = await provider.ValidateOptionArgumentsAsync(option, ["1.5s"]).ConfigureAwait(false); | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Assert.IsTrue(validResult.IsValid, "1.5s should be valid when using invariant culture"); | ||
|
|
||
|
Check failure on line 249 in test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs
|
||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // This should fail because comma is not valid in invariant culture | ||
| ValidationResult invalidResult = await provider.ValidateOptionArgumentsAsync(option, ["1,5s"]).ConfigureAwait(false); | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Assert.IsFalse(invalidResult.IsValid, "1,5s should be invalid when using invariant culture"); | ||
| } | ||
| finally | ||
| { | ||
| // Restore original culture | ||
| CultureInfo.CurrentCulture = originalCulture; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.