Skip to content

Commit

Permalink
Extend NativeAOT Templates tests to cover all supported platforms (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanpovazan authored Apr 15, 2024
1 parent a08c573 commit d22dece
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
35 changes: 8 additions & 27 deletions src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public void BuildWindowsAppSDKSelfContained(string id, bool wasdkself, bool nets

[Test]
[TestCase("maui", $"{DotNetCurrent}-ios", "ios-arm64")]
[TestCase("maui", $"{DotNetCurrent}-ios", "iossimulator-arm64")]
[TestCase("maui", $"{DotNetCurrent}-ios", "iossimulator-x64")]
[TestCase("maui", $"{DotNetCurrent}-maccatalyst", "maccatalyst-arm64")]
[TestCase("maui", $"{DotNetCurrent}-maccatalyst", "maccatalyst-x64")]
public void PublishNativeAOT(string id, string framework, string runtimeIdentifier)
{
if (!TestEnvironment.IsMacOS)
Expand All @@ -216,40 +220,17 @@ public void PublishNativeAOT(string id, string framework, string runtimeIdentifi

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("IlcTreatWarningsAsErrors=false");

Assert.IsTrue(DotnetInternal.Publish(projectFile, "Release", framework: framework, properties: extendedBuildProps, runtimeIdentifier: runtimeIdentifier),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

[Test]
[TestCase("maui", $"{DotNetCurrent}-ios", "ios-arm64")]
public void PublishNativeAOTCheckWarnings(string id, string framework, string runtimeIdentifier)
{
if (!TestEnvironment.IsMacOS)
Assert.Ignore("Publishing a MAUI iOS app with NativeAOT is only supported on a host MacOS system.");

var projectDir = TestDirectory;
var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj");

Assert.IsTrue(DotnetInternal.New(id, projectDir, DotNetCurrent),
$"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("PublishAotUsingRuntimePack=true"); // TODO: This parameter will become obsolete https://github.com/dotnet/runtime/issues/87060 in net9
extendedBuildProps.Add("_IsPublishing=true"); // This makes 'dotnet build -r iossimulator-x64' equivalent to 'dotnet publish -r iossimulator-x64'
extendedBuildProps.Add("IlcTreatWarningsAsErrors=false");
extendedBuildProps.Add("TrimmerSingleWarn=false");

string binLogFilePath = $"publish-{DateTime.UtcNow.ToFileTimeUtc()}.binlog";
Assert.IsTrue(DotnetInternal.Publish(projectFile, "Release", framework: framework, properties: extendedBuildProps, runtimeIdentifier: runtimeIdentifier, binlogPath: binLogFilePath),
Assert.IsTrue(DotnetInternal.Build(projectFile, "Release", framework: framework, properties: extendedBuildProps, runtimeIdentifier: runtimeIdentifier, binlogPath: binLogFilePath),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");

var expectedWarnings = BuildWarningsUtilities.ExpectedNativeAOTWarnings;
var actualWarnings = BuildWarningsUtilities.ReadNativeAOTWarningsFromBinLog(binLogFilePath);

actualWarnings.AssertWarnings(expectedWarnings);
actualWarnings.AssertNoWarnings();
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class WarningsPerFile
{
public string File { get; set; } = string.Empty;
public List<WarningsPerCode> WarningsPerCode { get; set; } = new List<WarningsPerCode>();
public override string ToString() => string.Join("\n", WarningsPerCode.SelectMany(warningPerCode => warningPerCode.Messages.Select(message => $"{File}: {warningPerCode.Code}: {message}")).ToList());
}

public class WarningsPerCode
Expand Down Expand Up @@ -82,6 +83,11 @@ private static void AddActualWarning(this List<WarningsPerFile> warnings, string
}
}

public static void AssertNoWarnings(this List<WarningsPerFile> actualWarnings)
{
Assert.AreEqual(0, actualWarnings.Count, $"No warnings expected, but got {actualWarnings.Count} warnings:\n{string.Join("\n", actualWarnings.Select(actualWarning => actualWarning.ToString()))}");
}

public static void AssertWarnings(this List<WarningsPerFile> actualWarnings, List<WarningsPerFile> expectedWarnings)
{
foreach (var expectedWarningsPerFile in expectedWarnings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ private static string ConstructBuildArgs(string projectFile, string config, stri
return buildArgs;
}

public static bool Build(string projectFile, string config, string target = "", string framework = "", IEnumerable<string>? properties = null, string binlogPath = "", bool msbuildWarningsAsErrors = false)
public static bool Build(string projectFile, string config, string target = "", string framework = "", IEnumerable<string>? properties = null, string binlogPath = "", bool msbuildWarningsAsErrors = false, string runtimeIdentifier = "")
{
var buildArgs = ConstructBuildArgs(projectFile, config, target, framework, properties, binlogPath);
var buildArgs = ConstructBuildArgs(projectFile, config, target, framework, properties, binlogPath, runtimeIdentifier, false);

if (msbuildWarningsAsErrors)
{
Expand Down

0 comments on commit d22dece

Please sign in to comment.