From 97644ed4cecbfb72a45fb7ff06d8f43bdef4ac12 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 11 Sep 2024 16:04:01 -0700 Subject: [PATCH] Add NativeAOT test scenarios (#43292) --- .../GivenThatWeWantToPublishAnAotApp.cs | 60 +++++++++++++++++-- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index 85473ebe5cd4..a322cc2dd46c 100644 --- a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -734,6 +734,59 @@ public void NativeAot_compiler_runs_when_PublishAot_is_enabled(string targetFram .And.HaveStdOutContaining("Hello world"); } + [RequiresMSBuildVersionTheory("17.0.0.32901")] + [InlineData(ToolsetInfo.CurrentTargetFramework)] + public void Warnings_are_generated_in_build_with_analyzers_enabled(string targetFramework) + { + + var projectName = "WarningAppWithPublishAotAnalyzersDisabled"; + + var testProject = CreateTestProjectWithAnalysisWarnings(targetFramework, projectName, true); + testProject.RecordProperties("NETCoreSdkPortableRuntimeIdentifier"); + testProject.AdditionalProperties["PublishAot"] = "true"; + testProject.AdditionalProperties["SelfContained"] = "true"; + // The below analyzers are enabled by default but explicitly setting them to true + testProject.AdditionalProperties["EnableAotAnalyzer"] = "true"; + testProject.AdditionalProperties["EnableTrimAnalyzer"] = "true"; + testProject.AdditionalProperties["EnableSingleFileAnalyzer"] = "true"; + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + var buildCommand = new BuildCommand(testAsset); + buildCommand + .Execute() + .Should().Pass() + .And.HaveStdOutContaining("warning IL3050") + .And.HaveStdOutContaining("warning IL3056") + .And.HaveStdOutContaining("warning IL2026") + .And.HaveStdOutContaining("warning IL3002"); + } + + [RequiresMSBuildVersionTheory("17.0.0.32901")] + [InlineData(ToolsetInfo.CurrentTargetFramework)] + public void Warnings_are_not_generated_in_build_with_analyzers_disabled(string targetFramework) + { + + var projectName = "WarningAppWithPublishAotAnalyzersDisabled"; + + var testProject = CreateTestProjectWithAnalysisWarnings(targetFramework, projectName, true); + testProject.RecordProperties("NETCoreSdkPortableRuntimeIdentifier"); + testProject.AdditionalProperties["PublishAot"] = "true"; + testProject.AdditionalProperties["SelfContained"] = "true"; + testProject.AdditionalProperties["EnableAotAnalyzer"] = "false"; + testProject.AdditionalProperties["EnableTrimAnalyzer"] = "false"; + testProject.AdditionalProperties["EnableSingleFileAnalyzer"] = "false"; + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + var buildCommand = new BuildCommand(testAsset); + buildCommand + .Execute() + .Should().Pass() + .And.NotHaveStdOutContaining("warning IL3050") + .And.NotHaveStdOutContaining("warning IL3056") + .And.NotHaveStdOutContaining("warning IL2026") + .And.NotHaveStdOutContaining("warning IL3002"); + } + [RequiresMSBuildVersionTheory("17.0.0.32901")] [InlineData(ToolsetInfo.CurrentTargetFramework)] public void Warnings_are_generated_even_with_analyzers_disabled(string targetFramework) @@ -824,13 +877,10 @@ public void NativeAotLib_warns_when_eventpipe_is_enabled(string libType) var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); - // Revisit once the issue is fixed - // https://github.com/dotnet/runtime/issues/89346 publishCommand .Execute() - .Should().Pass(); - // Comment in the following code when https://github.com/dotnet/sdk/issues/34839 gets fixed - // .And.HaveStdOutContaining("EventSource is not supported or recommended when compiling to a native library"); + .Should().Pass() + .And.HaveStdOutContaining("EventSource is not supported or recommended when compiling to a native library"); } [RequiresMSBuildVersionTheory("17.0.0.32901")]