From ef8bbeecdb0641c29a0bf0b9d2bd8632b65e6e23 Mon Sep 17 00:00:00 2001 From: Ivan Povazan Date: Wed, 17 Jan 2024 10:55:49 +0100 Subject: [PATCH] Reuse RunOniOS test method for NativeAOT --- .../AppleTemplateTests.cs | 53 +++++++------------ .../BaseBuildTest.cs | 6 +++ 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AppleTemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AppleTemplateTests.cs index 786d297a64a3..0176952e17c5 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AppleTemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AppleTemplateTests.cs @@ -25,15 +25,16 @@ public void AppleTemplateFxtTearDown() } [Test] - [TestCase("maui", "Debug", DotNetPrevious)] - [TestCase("maui", "Release", DotNetPrevious)] - [TestCase("maui", "Debug", DotNetCurrent)] - [TestCase("maui", "Release", DotNetCurrent)] - [TestCase("maui-blazor", "Debug", DotNetPrevious)] - [TestCase("maui-blazor", "Release", DotNetPrevious)] - [TestCase("maui-blazor", "Debug", DotNetCurrent)] - [TestCase("maui-blazor", "Release", DotNetCurrent)] - public void RunOniOS(string id, string config, string framework) + [TestCase("maui", "Debug", DotNetPrevious, "iossimulator-x64", RuntimeVariant.Mono)] + [TestCase("maui", "Release", DotNetPrevious, "iossimulator-x64", RuntimeVariant.Mono)] + [TestCase("maui", "Debug", DotNetCurrent, "iossimulator-x64", RuntimeVariant.Mono)] + [TestCase("maui", "Release", DotNetCurrent, "iossimulator-x64", RuntimeVariant.Mono)] + [TestCase("maui-blazor", "Debug", DotNetPrevious, "iossimulator-x64", RuntimeVariant.Mono)] + [TestCase("maui-blazor", "Release", DotNetPrevious, "iossimulator-x64", RuntimeVariant.Mono)] + [TestCase("maui-blazor", "Debug", DotNetCurrent, "iossimulator-x64", RuntimeVariant.Mono)] + [TestCase("maui-blazor", "Release", DotNetCurrent, "iossimulator-x64", RuntimeVariant.Mono)] + [TestCase("maui", "Release", DotNetCurrent, "iossimulator-x64", RuntimeVariant.NativeAOT)] + public void RunOniOS(string id, string config, string framework, string runtimeIdentifier, RuntimeVariant runtimeVariant) { var projectDir = TestDirectory; var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj"); @@ -41,32 +42,16 @@ public void RunOniOS(string id, string config, string framework) Assert.IsTrue(DotnetInternal.New(id, projectDir, framework), $"Unable to create template {id}. Check test output for errors."); - Assert.IsTrue(DotnetInternal.Build(projectFile, config, framework: $"{framework}-ios", properties: BuildProps), - $"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors."); - - var appFile = Path.Combine(projectDir, "bin", config, $"{framework}-ios", "iossimulator-x64", $"{Path.GetFileName(projectDir)}.app"); - - Assert.IsTrue(XHarness.RunAppleForTimeout(appFile, Path.Combine(projectDir, "xh-results"), TestSimulator.XHarnessID), - $"Project {Path.GetFileName(projectFile)} failed to run. Check test output/attachments for errors."); - } - - [Test] - [TestCase("maui", "Release", DotNetCurrent, "iossimulator-x64")] - public void RunOniOSNativeAOT(string id, string config, string framework, string runtimeIdentifier) - { - var projectDir = TestDirectory; - var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj"); - - Assert.IsTrue(DotnetInternal.New(id, projectDir, framework), - $"Unable to create template {id}. Check test output for errors."); - - var extendedBuildProps = BuildProps; - extendedBuildProps.Add("PublishAot=true"); - extendedBuildProps.Add("PublishAotUsingRuntimePack=true"); // TODO: This parameter will become obsolete https://github.com/dotnet/runtime/issues/87060 - extendedBuildProps.Add("_IsPublishing=true"); // using dotnet build with -p:_IsPublishing=true enables targeting simulators - extendedBuildProps.Add($"RuntimeIdentifier={runtimeIdentifier}"); + var buildProps = BuildProps; + if (runtimeVariant == RuntimeVariant.NativeAOT) + { + buildProps.Add("PublishAot=true"); + buildProps.Add("PublishAotUsingRuntimePack=true"); // TODO: This parameter will become obsolete https://github.com/dotnet/runtime/issues/87060 + buildProps.Add("_IsPublishing=true"); // using dotnet build with -p:_IsPublishing=true enables targeting simulators + buildProps.Add($"RuntimeIdentifier={runtimeIdentifier}"); + } - Assert.IsTrue(DotnetInternal.Build(projectFile, config, framework: $"{framework}-ios", properties: BuildProps), + Assert.IsTrue(DotnetInternal.Build(projectFile, config, framework: $"{framework}-ios", properties: buildProps), $"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors."); var appFile = Path.Combine(projectDir, "bin", config, $"{framework}-ios", runtimeIdentifier, $"{Path.GetFileName(projectDir)}.app"); diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseBuildTest.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseBuildTest.cs index 15e97d03fa04..f10ab79992e7 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseBuildTest.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseBuildTest.cs @@ -1,6 +1,12 @@  namespace Microsoft.Maui.IntegrationTests { + public enum RuntimeVariant + { + Mono, + NativeAOT + } + public class BaseBuildTest { public const string DotNetCurrent = "net8.0";