From a72754cff17cf1d9c0fffbd396f980e2b0a6f248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 14 May 2024 14:30:15 +0200 Subject: [PATCH 1/5] Check downlevel runtime versions --- .../wasm/Wasm.Build.Tests/DownLevelCheck.cs | 74 +++++++++++++++++++ .../Wasm.Build.Tests/DownlevelVersions.cs.in | 8 ++ .../Wasm.Build.Tests/Wasm.Build.Tests.csproj | 19 +++++ 3 files changed, 101 insertions(+) create mode 100644 src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs create mode 100644 src/mono/wasm/Wasm.Build.Tests/DownlevelVersions.cs.in diff --git a/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs b/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs new file mode 100644 index 00000000000000..0ff73762301f11 --- /dev/null +++ b/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Xunit; +using Xunit.Abstractions; + +namespace Wasm.Build.Tests +{ + public class DownlevelCheck : BuildTestBase + { + public DownlevelCheck(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) + : base(new TestMainJsProjectProvider(output), output, buildContext) + { + } + + private const string ProjectTemplate = + """ + + + {TargetFramework} + Exe + + + + + + """; + + private string FormatTestMessage(string version) => $"TEST::TargetingPackVersion::{version}::TEST"; + + public static IEnumerable GetData() => new[] + { + new object[] { "net6.0", DownlevelVersions.PackageVersionNet6 }, + new object[] { "net7.0", DownlevelVersions.PackageVersionNet7 }, + new object[] { "net8.0", DownlevelVersions.PackageVersionNet8 }, + }; + + [Theory] + [MemberData(nameof(GetData))] + public void TestComputedVersions(string targetFramework, Version computedVersion) + { + string id = $"DownlevelCheck_{targetFramework}_{GetRandomId()}"; + string projectContent = ProjectTemplate + .Replace("{TargetFramework}", targetFramework) + .Replace("{TestMessage}", FormatTestMessage("@(ResolvedFrameworkReference->'%(TargetingPackVersion)')")); + + InitPaths(id); + InitProjectDir(_projectDir); + File.WriteAllText(Path.Combine(_projectDir, $"{id}.csproj"), projectContent); + File.WriteAllText(Path.Combine(_projectDir, $"Program.cs"), "System.Console.WriteLine(\"Hello, World!\");"); // no-op + + (var result, _) = BuildProjectWithoutAssert(id, "Release", new( + AssertAppBundle: false, + CreateProject: false, + Publish: false, + TargetFramework: targetFramework + )); + + var versionExtractor = new Regex(FormatTestMessage("([0-9]+.[0-9]+.[0-9]+)")); + var match = versionExtractor.Match(result.Output); + Assert.True(match.Success, $"Expected to find a version in the output, but got: {result.Output}"); + + if (!Version.TryParse(match.Groups[1].Value, out var actualVersion)) + Assert.Fail($"Unable to parse version from regex match '{match.Groups[1].Value}'"); + + Assert.True(actualVersion >= computedVersion, $"Actually used version is not greater-or-equal then computed version in repository: (actually used version) '{actualVersion}' >= (computed version in repository) '{Versions.PackageVersionNet8}'"); + } + } +} diff --git a/src/mono/wasm/Wasm.Build.Tests/DownlevelVersions.cs.in b/src/mono/wasm/Wasm.Build.Tests/DownlevelVersions.cs.in new file mode 100644 index 00000000000000..63a187a362f684 --- /dev/null +++ b/src/mono/wasm/Wasm.Build.Tests/DownlevelVersions.cs.in @@ -0,0 +1,8 @@ +using System; + +public static class DownlevelVersions +{ + public static readonly Version PackageVersionNet6 = Version.Parse("${PackageVersionNet6}"); + public static readonly Version PackageVersionNet7 = Version.Parse("${PackageVersionNet7}"); + public static readonly Version PackageVersionNet8 = Version.Parse("${PackageVersionNet8}"); +} \ No newline at end of file diff --git a/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj b/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj index 62601dd54d85bc..628f16034ca536 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj +++ b/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj @@ -46,6 +46,7 @@ + @@ -55,6 +56,24 @@ + + + <_DownlevelVersionsOutputPath>$(IntermediateOutputPath)\DownlevelVersions.cs + + + <_DownlevelVersionsProperty Include="PackageVersionNet6" Value="$(PackageVersionNet6)" /> + <_DownlevelVersionsProperty Include="PackageVersionNet7" Value="$(PackageVersionNet7)" /> + <_DownlevelVersionsProperty Include="PackageVersionNet8" Value="$(PackageVersionNet8)" /> + + + + + + + From 1810964bd222d5aab6d105b6934d889dd4bd8384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 14 May 2024 14:53:49 +0200 Subject: [PATCH 2/5] Feedback --- src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs b/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs index 0ff73762301f11..9198fde7f6c89a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs +++ b/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs @@ -68,7 +68,7 @@ public void TestComputedVersions(string targetFramework, Version computedVersion if (!Version.TryParse(match.Groups[1].Value, out var actualVersion)) Assert.Fail($"Unable to parse version from regex match '{match.Groups[1].Value}'"); - Assert.True(actualVersion >= computedVersion, $"Actually used version is not greater-or-equal then computed version in repository: (actually used version) '{actualVersion}' >= (computed version in repository) '{Versions.PackageVersionNet8}'"); + Assert.True(actualVersion >= computedVersion, $"Actually used version is lower then computed version in repository: (actually used version) '{actualVersion}' >= (computed version in repository) '{Versions.PackageVersionNet8}'"); } } } From 311d32da086a1e38ad7f3df4acb04f733d8ce479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 14 May 2024 15:54:10 +0200 Subject: [PATCH 3/5] Fix using wrong variable --- src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs b/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs index 9198fde7f6c89a..48734f043652e1 100644 --- a/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs +++ b/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs @@ -68,7 +68,7 @@ public void TestComputedVersions(string targetFramework, Version computedVersion if (!Version.TryParse(match.Groups[1].Value, out var actualVersion)) Assert.Fail($"Unable to parse version from regex match '{match.Groups[1].Value}'"); - Assert.True(actualVersion >= computedVersion, $"Actually used version is lower then computed version in repository: (actually used version) '{actualVersion}' >= (computed version in repository) '{Versions.PackageVersionNet8}'"); + Assert.True(actualVersion >= computedVersion, $"Actually used version is lower then computed version in repository: (actually used version) '{actualVersion}' >= (computed version in repository) '{computedVersion}'"); } } } From f21cbb546194133bdd415c9f12f83245578e784a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 16 May 2024 09:05:53 +0200 Subject: [PATCH 4/5] Register the test to run --- eng/testing/scenarios/BuildWasmAppsJobsList.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/testing/scenarios/BuildWasmAppsJobsList.txt b/eng/testing/scenarios/BuildWasmAppsJobsList.txt index 11bfdab2c7414e..df0ef94f26facc 100644 --- a/eng/testing/scenarios/BuildWasmAppsJobsList.txt +++ b/eng/testing/scenarios/BuildWasmAppsJobsList.txt @@ -47,3 +47,4 @@ Wasm.Build.Tests.WasmTemplateTests Wasm.Build.Tests.WorkloadTests Wasm.Build.Tests.MT.Blazor.SimpleMultiThreadedTests Wasm.Build.Tests.TestAppScenarios.DebugLevelTests +Wasm.Build.Tests.DownlevelCheck From 6bb0850a5eabd2f294b77ad247ef2346739ca646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 16 May 2024 09:06:21 +0200 Subject: [PATCH 5/5] Whitespace --- src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs b/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs index 48734f043652e1..5372d4dba5c141 100644 --- a/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs +++ b/src/mono/wasm/Wasm.Build.Tests/DownLevelCheck.cs @@ -14,7 +14,7 @@ namespace Wasm.Build.Tests public class DownlevelCheck : BuildTestBase { public DownlevelCheck(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) - : base(new TestMainJsProjectProvider(output), output, buildContext) + : base(new TestMainJsProjectProvider(output), output, buildContext) { }