|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.IO; |
| 6 | +using Xunit; |
| 7 | +using Xunit.Abstractions; |
| 8 | + |
| 9 | +#nullable enable |
| 10 | + |
| 11 | +namespace Wasm.Build.Tests |
| 12 | +{ |
| 13 | + public class InvariantTimezoneTests : BuildTestBase |
| 14 | + { |
| 15 | + public InvariantTimezoneTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) |
| 16 | + : base(output, buildContext) |
| 17 | + { |
| 18 | + } |
| 19 | + |
| 20 | + public static IEnumerable<object?[]> InvariantTimezoneTestData(bool aot, RunHost host) |
| 21 | + => ConfigWithAOTData(aot) |
| 22 | + .Multiply( |
| 23 | + new object?[] { null }, |
| 24 | + new object?[] { false }, |
| 25 | + new object?[] { true }) |
| 26 | + .WithRunHosts(host) |
| 27 | + .UnwrapItemsAsArrays(); |
| 28 | + |
| 29 | + [Theory] |
| 30 | + [MemberData(nameof(InvariantTimezoneTestData), parameters: new object[] { /*aot*/ false, RunHost.All })] |
| 31 | + [MemberData(nameof(InvariantTimezoneTestData), parameters: new object[] { /*aot*/ true, RunHost.All })] |
| 32 | + public void AOT_InvariantTimezone(BuildArgs buildArgs, bool? invariantTimezone, RunHost host, string id) |
| 33 | + => TestInvariantTimezone(buildArgs, invariantTimezone, host, id); |
| 34 | + |
| 35 | + [Theory] |
| 36 | + [MemberData(nameof(InvariantTimezoneTestData), parameters: new object[] { /*aot*/ false, RunHost.All })] |
| 37 | + public void RelinkingWithoutAOT(BuildArgs buildArgs, bool? invariantTimezone, RunHost host, string id) |
| 38 | + => TestInvariantTimezone(buildArgs, invariantTimezone, host, id, |
| 39 | + extraProperties: "<WasmBuildNative>true</WasmBuildNative>", |
| 40 | + dotnetWasmFromRuntimePack: false); |
| 41 | + |
| 42 | + private void TestInvariantTimezone(BuildArgs buildArgs, bool? invariantTimezone, |
| 43 | + RunHost host, string id, string extraProperties="", bool? dotnetWasmFromRuntimePack=null) |
| 44 | + { |
| 45 | + string projectName = $"invariant_{invariantTimezone?.ToString() ?? "unset"}"; |
| 46 | + if (invariantTimezone != null) |
| 47 | + extraProperties = $"{extraProperties}<InvariantTimezone>{invariantTimezone}</InvariantTimezone>"; |
| 48 | + |
| 49 | + buildArgs = buildArgs with { ProjectName = projectName }; |
| 50 | + buildArgs = ExpandBuildArgs(buildArgs, extraProperties); |
| 51 | + |
| 52 | + if (dotnetWasmFromRuntimePack == null) |
| 53 | + dotnetWasmFromRuntimePack = !(buildArgs.AOT || buildArgs.Config == "Release"); |
| 54 | + |
| 55 | + BuildProject(buildArgs, |
| 56 | + id: id, |
| 57 | + new BuildProjectOptions( |
| 58 | + InitProject: () => File.Copy(Path.Combine(BuildEnvironment.TestAssetsPath, "Wasm.Buid.Tests.Programs", "InvariantTimezone.cs"), Path.Combine(_projectDir!, "Program.cs")), |
| 59 | + DotnetWasmFromRuntimePack: dotnetWasmFromRuntimePack)); |
| 60 | + |
| 61 | + string output = RunAndTestWasmApp(buildArgs, expectedExitCode: 42, host: host, id: id); |
| 62 | + Assert.Contains("UTC BaseUtcOffset is 0", output); |
| 63 | + if (invariantTimezone == true) |
| 64 | + { |
| 65 | + Assert.Contains("Could not find Asia/Tokyo", output); |
| 66 | + } |
| 67 | + else |
| 68 | + { |
| 69 | + Assert.Contains("Asia/Tokyo BaseUtcOffset is 09:00:00", output); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments