Skip to content

Commit 6d15a02

Browse files
authored
[wasm] Fix invariant globalization test (#56121)
The following commit changed the behavior to throw `CultureNotFoundException` when creating cultures in invariant mode. ``` commit 04dac7b Author: Tarek Mahmoud Sayed <tarekms@microsoft.com> Date: Thu Jul 1 11:55:05 2021 -0700 Allow restricting cultures creation with any arbitrary names in Globalization Invariant Mode (#54247) ``` This commit updates the corresponding test in `Wasm.Build.Tests` to handle that explicitly. Fixes #55838
1 parent f28702c commit 6d15a02

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/tests/BuildWasmApps/Wasm.Build.Tests/InvariantGlobalizationTests.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,41 @@ private void TestInvariantGlobalization(BuildArgs buildArgs, bool? invariantGlob
5757
string programText = @"
5858
using System;
5959
using System.Globalization;
60-
using System.Threading.Tasks;
6160
62-
public class TestClass {
63-
public static int Main()
64-
{
65-
CultureInfo culture;
66-
try
67-
{
68-
culture = new CultureInfo(""es-ES"", false);
69-
// https://github.com/dotnet/runtime/blob/main/docs/design/features/globalization-invariant-mode.md#cultures-and-culture-data
70-
}
71-
catch
72-
{
73-
culture = new CultureInfo("""", false);
74-
}
75-
Console.WriteLine($""{culture.LCID == CultureInfo.InvariantCulture.LCID} - {culture.NativeName}"");
76-
return 42;
77-
}
78-
}";
61+
// https://github.com/dotnet/runtime/blob/main/docs/design/features/globalization-invariant-mode.md#cultures-and-culture-data
62+
try
63+
{
64+
CultureInfo culture = new (""es-ES"", false);
65+
Console.WriteLine($""es-ES: Is Invariant LCID: {culture.LCID == CultureInfo.InvariantCulture.LCID}, NativeName: {culture.NativeName}"");
66+
}
67+
catch (CultureNotFoundException cnfe)
68+
{
69+
Console.WriteLine($""Could not create es-ES culture: {cnfe.Message}"");
70+
}
71+
72+
Console.WriteLine($""CurrentCulture.NativeName: {CultureInfo.CurrentCulture.NativeName}"");
73+
return 42;
74+
";
7975

8076
BuildProject(buildArgs,
8177
initProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), programText),
8278
id: id,
8379
dotnetWasmFromRuntimePack: dotnetWasmFromRuntimePack,
8480
hasIcudt: invariantGlobalization == null || invariantGlobalization.Value == false);
8581

86-
string expectedOutputString = invariantGlobalization == true
87-
? "True - Invariant Language (Invariant Country)"
88-
: "False - es (ES)";
89-
RunAndTestWasmApp(buildArgs, expectedExitCode: 42,
90-
test: output => Assert.Contains(expectedOutputString, output), host: host, id: id);
82+
if (invariantGlobalization == true)
83+
{
84+
string output = RunAndTestWasmApp(buildArgs, expectedExitCode: 42, host: host, id: id);
85+
Assert.Contains("Could not create es-ES culture", output);
86+
Assert.Contains("CurrentCulture.NativeName: Invariant Language (Invariant Country)", output);
87+
}
88+
else
89+
{
90+
string output = RunAndTestWasmApp(buildArgs, expectedExitCode: 42, host: host, id: id);
91+
Assert.Contains("es-ES: Is Invariant LCID: False, NativeName: es (ES)", output);
92+
93+
// ignoring the last line of the output which prints the current culture
94+
}
9195
}
9296
}
9397
}

0 commit comments

Comments
 (0)