Skip to content

Commit

Permalink
Add NativeAOT test scenarios (#43292)
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshanF authored Sep 11, 2024
1 parent 45f6f6b commit 97644ed
Showing 1 changed file with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")]
Expand Down

0 comments on commit 97644ed

Please sign in to comment.