From f2a5bc83beb4a771705cf2613b521c81f725a0bc Mon Sep 17 00:00:00 2001 From: Jason Zhai Date: Fri, 7 Feb 2025 18:35:42 -0800 Subject: [PATCH 1/2] Fix NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled Test --- .../GivenThatWeWantToPublishAnAotApp.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index d136a7f9e3d4..9417f7eb2cd5 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -39,7 +39,25 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string { testProject.AdditionalProperties["StripSymbols"] = "true"; } - var testAsset = _testAssetsManager.CreateTestProject(testProject); + var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework); + + string[] ignoredPatterns = null; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + ignoredPatterns = new string[] + { + // Both these exclusions can be removed once the min tested version is .NET 10 and the min supported + // XCode version is XCode 16. + + // -ld_classic option is required to workaround bugs in XCode 15 and .NET 9 and older runtimes. + // See https://github.com/dotnet/runtime/issues/97745 for details. + "ld: warning: -ld_classic is deprecated and will be removed in a future release", + // These warnings show up when dotnet/runtime compiled using Apple clang 15+ is used + // with classic linker (either Apple clang 14 or clang 15+ with -ld_classic). + "ld: warning: __LD,__compact_unwind entries for", + }; + } var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand @@ -48,7 +66,7 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string .And.NotHaveStdOutContaining("IL2026") .And.NotHaveStdErrContaining("NETSDK1179") .And.NotHaveStdErrContaining("warning") - .And.NotHaveStdOutContaining("warning"); + .And.NotHaveStdOutContaining("warning", ignoredPatterns); var buildProperties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework); var rid = buildProperties["NETCoreSdkPortableRuntimeIdentifier"]; From d194627f054935f0d9a0ae0cb7943c4b0c9a199e Mon Sep 17 00:00:00 2001 From: Jason Zhai Date: Fri, 7 Feb 2025 18:56:16 -0800 Subject: [PATCH 2/2] Add ignoredPatterns parameter to NotHaveStdOutContaining method --- .../Assertions/CommandResultAssertions.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.TestFramework/Assertions/CommandResultAssertions.cs b/src/Tests/Microsoft.NET.TestFramework/Assertions/CommandResultAssertions.cs index 176dee7b5dac..0077c1793652 100644 --- a/src/Tests/Microsoft.NET.TestFramework/Assertions/CommandResultAssertions.cs +++ b/src/Tests/Microsoft.NET.TestFramework/Assertions/CommandResultAssertions.cs @@ -66,10 +66,23 @@ public AndConstraint HaveStdOutContaining(Func(this); } - public AndConstraint NotHaveStdOutContaining(string pattern) + public AndConstraint NotHaveStdOutContaining(string pattern, string[] ignoredPatterns = null) { - Execute.Assertion.ForCondition(!_commandResult.StdOut.Contains(pattern)) + string filteredStdOut = _commandResult.StdOut; + if (ignoredPatterns != null && ignoredPatterns.Length > 0) + { + foreach (var ignoredPattern in ignoredPatterns) + { + filteredStdOut = string.Join(Environment.NewLine, filteredStdOut + .Split(new[] { Environment.NewLine }, StringSplitOptions.None) + .Where(line => !line.Contains(ignoredPattern))); + } + } + + // Perform the assertion on the filtered output + Execute.Assertion.ForCondition(!filteredStdOut.Contains(pattern)) .FailWith(AppendDiagnosticsTo($"The command output contained a result it should not have contained: {pattern}{Environment.NewLine}")); + return new AndConstraint(this); }