From abcec04b752f26a130498db289d4d67a6c2b8f97 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 2 Oct 2024 19:51:31 +0200 Subject: [PATCH] Revert "[msbuild/tests] Use 'dotnet test' for the MSBuild tests. (#21263)" (#21356) This reverts commit 15c1e7527e8d621760b9fe2c6b1ce2382dcab2f7. It breaks the Windows tests. --- msbuild/ILMerge.targets | 2 +- .../Tasks/ComputeCodesignItems.cs | 2 +- tests/Makefile | 12 +++----- .../TaskTests/CompileAppManifestTaskTests.cs | 4 +-- .../TaskTests/CompileEntitlementsTaskTests.cs | 4 +-- .../ComputeCodesignItemsTaskTests.cs | 8 +++--- .../ResolveNativeReferencesTaskTest.cs | 4 +-- .../Xamarin.MacDev.Tasks.Tests.csproj | 14 +++++----- .../TestHelpers/BuildEngine.cs | 2 +- .../Xamarin.MacDev.Tests.csproj | 6 ++-- .../Jenkins/NUnitTestTasksEnumerable.cs | 28 +++++++++++-------- 11 files changed, 44 insertions(+), 42 deletions(-) diff --git a/msbuild/ILMerge.targets b/msbuild/ILMerge.targets index a0885f6875..35ff9af16f 100644 --- a/msbuild/ILMerge.targets +++ b/msbuild/ILMerge.targets @@ -2,7 +2,7 @@ true - false + true diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs index c001208bcb..085e9f067b 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs @@ -161,7 +161,7 @@ namespace Xamarin.MacDev.Tasks { for (var i = 1; i < all.Length; i++) { var nextMetadata = all [i].CloneCustomMetadataToDictionary (); if (nextMetadata.Count != firstMetadata.Count) { - Log.LogWarning (MSBStrings.W7095, /* Code signing has been requested multiple times for '{0}', with different metadata. The metadata for one are: '{1}', while the metadata for the other are: '{2}' */ group.Key, string.Join (", ", firstMetadata.Keys.OrderBy (v => v)), string.Join (", ", nextMetadata.Keys.OrderBy (v => v))); + Log.LogWarning (MSBStrings.W7095, /* Code signing has been requested multiple times for '{0}', with different metadata. The metadata for one are: '{1}', while the metadata for the other are: '{2}' */ group.Key, string.Join (", ", firstMetadata.Keys), string.Join (", ", nextMetadata.Keys)); } else { foreach (var kvp in firstMetadata) { if (!nextMetadata.TryGetValue (kvp.Key, out var nextValue)) { diff --git a/tests/Makefile b/tests/Makefile index 1e0462c77a..917286623b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -217,19 +217,15 @@ killall: NUNIT_MSBUILD_DIR=$(TOP)/packages/NUnit.Runners.2.6.4/tools/lib test-ios-tasks: test-macdev-tests test-macdev-tasks -# Example TEST_FILTER: -# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp" -# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details test-macdev-tests: export MSBUILD_EXE_PATH= test-macdev-tests: verify-system-vsmac-xcode-match - $(Q) $(DOTNET) test $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj $(TEST_FILTER) + $(Q) $(DOTNET) build "/bl:$@.binlog" $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj /p:Configuration=Debug $(DOTNET_BUILD_VERBOSITY) + cd $(TOP)/tests/msbuild/Xamarin.MacDev.Tests && $(SYSTEM_XIBUILD) -t -- $(abspath $(TOP)/tools/nunit3-console-3.11.1) $(abspath $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/bin/Debug/net472/Xamarin.MacDev.Tests.dll) "--result=$(abspath $(CURDIR)/TestResults_Xamarin.MacDev.Tests.xml);format=nunit2" -labels=After $(TEST_FIXTURE) -# Example TEST_FILTER: -# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp" -# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details test-macdev-tasks: export MSBUILD_EXE_PATH= test-macdev-tasks: verify-system-vsmac-xcode-match - $(Q) $(DOTNET) test $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj $(TEST_FILTER) + $(Q) $(DOTNET) build "/bl:$@.binlog" $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj /p:Configuration=Debug $(DOTNET_BUILD_VERBOSITY) + cd $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests && $(SYSTEM_XIBUILD) -t -- $(abspath $(TOP)/tools/nunit3-console-3.11.1) $(abspath $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests/bin/Debug/net472/Xamarin.MacDev.Tasks.Tests.dll) "--result=$(abspath $(CURDIR)/TestResults_Xamarin.MacDev.Tasks.Tests.xml)" -labels=After $(TEST_FIXTURE) mac-test-package.zip: ifdef INCLUDE_MAC diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs index 00c3fa08f9..94463d1d8a 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs @@ -21,8 +21,8 @@ namespace Xamarin.MacDev.Tasks { task.AssemblyName = "AssemblyName"; task.AppBundleName = "AppBundleName"; task.CompiledAppManifest = new TaskItem (Path.Combine (tmpdir, "TemporaryAppManifest.plist")); - task.DefaultSdkVersion = Sdks.GetAppleSdk (platform).GetInstalledSdkVersions (false).First ().ToString ()!; - task.SdkVersion = task.DefaultSdkVersion ?? string.Empty; + task.DefaultSdkVersion = Sdks.GetAppleSdk (platform).GetInstalledSdkVersions (false).First ().ToString (); + task.SdkVersion = task.DefaultSdkVersion; task.TargetFrameworkMoniker = TargetFramework.GetTargetFramework (platform, true).ToString (); return task; diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs index 17186c306f..00c90fc9d9 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs @@ -34,8 +34,8 @@ namespace Xamarin.MacDev.Tasks { task.AppBundleDir = AppBundlePath; task.BundleIdentifier = "com.xamarin.MySingleView"; task.CompiledEntitlements = new TaskItem (Path.Combine (MonoTouchProjectObjPath, "Entitlements.xcent")); - task.Entitlements = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "Entitlements.plist"); - task.ProvisioningProfile = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "profile.mobileprovision"); + task.Entitlements = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "Entitlements.plist"); + task.ProvisioningProfile = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "profile.mobileprovision"); task.SdkPlatform = "iPhoneOS"; task.SdkVersion = "6.1"; task.TargetFrameworkMoniker = "Xamarin.iOS,v1.0"; diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs index d72eecdb89..9255a818a2 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs @@ -496,7 +496,7 @@ namespace Xamarin.MacDev.Tasks { Assert.AreEqual (3, Engine.Logger.WarningsEvents.Count, "Warning Count"); Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata 'OnlyIn1=true' has been set for one item, but not the other.", Engine.Logger.WarningsEvents [0].Message, "Message #0"); Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata 'InOneAndTwoWithDifferentValues' has different values for each item (once it's '1', another time it's '2').", Engine.Logger.WarningsEvents [1].Message, "Message #1"); - Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata for one are: 'CodesignStampFile, InOneAndTwoWithDifferentValues, OnlyIn1, RequireCodeSigning', while the metadata for the other are: 'CodesignStampFile, RequireCodeSigning'", Engine.Logger.WarningsEvents [2].Message, "Message #2"); + Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata for one are: 'RequireCodeSigning, OnlyIn1, InOneAndTwoWithDifferentValues, CodesignStampFile', while the metadata for the other are: 'RequireCodeSigning, CodesignStampFile'", Engine.Logger.WarningsEvents [2].Message, "Message #2"); VerifyCodesigningResults (infos, task.OutputCodesignItems, platform); } finally { @@ -532,7 +532,7 @@ namespace Xamarin.MacDev.Tasks { var metadata = item.GetMetadata (kvp.Key); if (metadata == string.Empty && kvp.Value != string.Empty) { failures.Add ($"Item '{info.ItemSpec}': Expected metadata '{kvp.Key}' not found (with value '{kvp.Value}')."); - } else if (!string.Equals (metadata, kvp.Value, StringComparison.Ordinal)) { + } else if (!string.Equals (metadata, kvp.Value)) { failures.Add ($"Item '{info.ItemSpec}': Expected value '{kvp.Value}' for metadata '{kvp.Key}', but got '{metadata}' instead.\nExpected: {kvp.Value}\nActual: {metadata}"); } } @@ -587,7 +587,7 @@ namespace Xamarin.MacDev.Tasks { if (file.EndsWith (".appex", StringComparison.OrdinalIgnoreCase) || file.EndsWith (".app", StringComparison.OrdinalIgnoreCase)) { Directory.CreateDirectory (f); } else { - Directory.CreateDirectory (Path.GetDirectoryName (file)!); + Directory.CreateDirectory (Path.GetDirectoryName (file)); File.WriteAllText (file, string.Empty); } } @@ -637,7 +637,7 @@ namespace Xamarin.MacDev.Tasks { { var rv = new Dictionary (); foreach (DictionaryEntry de in self.CloneCustomMetadata ()) { - rv [(string) de.Key!] = (string) de.Value!; + rv [(string) de.Key] = (string) de.Value; } return rv; } diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs index 1488497793..838d1be627 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs @@ -38,7 +38,7 @@ namespace Xamarin.MacDev.Tasks.Tests { // some architecture changes recently, e.g. // in Xcode 12.1+ watchOS does not have an i386 architecture anymore // on Xcode 12.2+ you get arm64 for all (iOS, tvOS and watchOS) simulators - var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "xcf-xcode12.2.plist"); + var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-xcode12.2.plist"); var plist = PDictionary.FromFile (path)!; var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath); Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result"); @@ -51,7 +51,7 @@ namespace Xamarin.MacDev.Tasks.Tests { [TestCase (TargetFramework.Xamarin_WatchOS_1_0_String, true, "i386", "watchos-i386-simulator/XTest.framework/XTest")] public void PreXcode12 (string targetFrameworkMoniker, bool isSimulator, string architecture, string expected) { - var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "xcf-prexcode12.plist"); + var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-prexcode12.plist"); var plist = PDictionary.FromFile (path)!; var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath); Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result"); diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj index a01b20140e..126d96deee 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj @@ -1,7 +1,7 @@ - net$(BundledNETCoreAppTargetFrameworkVersion) + net472 false true latest @@ -32,12 +32,12 @@ - - - - - - + + + + + + diff --git a/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs b/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs index 8043c18754..59b130f99d 100644 --- a/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs +++ b/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs @@ -246,7 +246,7 @@ namespace Xamarin.Tests { foreach (var prop in properties) args.Add ($"/p:{prop.Key}={prop.Value}"); } - var binlog = Path.Combine (Path.GetDirectoryName (project)!, $"log-{target}-{DateTime.Now:yyyyMMdd_HHmmss}.binlog"); + var binlog = Path.Combine (Path.GetDirectoryName (project), $"log-{target}-{DateTime.Now:yyyyMMdd_HHmmss}.binlog"); args.Add ($"/bl:{binlog}"); var output = new StringBuilder (); diff --git a/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj b/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj index 771e95f8bc..87ff486907 100644 --- a/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj +++ b/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj @@ -1,7 +1,7 @@ - net$(BundledNETCoreAppTargetFrameworkVersion) + net472 false true latest @@ -11,8 +11,8 @@ - - + + diff --git a/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs b/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs index bc991bce25..8b807022b6 100644 --- a/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs +++ b/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs @@ -19,24 +19,27 @@ namespace Xharness.Jenkins { public IEnumerator GetEnumerator () { - var msbuildTasksTestsProject = new TestProject (TestLabel.Msbuild, Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tasks.Tests", "Xamarin.MacDev.Tasks.Tests.csproj"))) { + var netstandard2Project = new TestProject (TestLabel.Msbuild, Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tasks.Tests", "Xamarin.MacDev.Tasks.Tests.csproj"))) { IsDotNetProject = true, }; var env = new Dictionary { { "SYSTEM_MONO", this.jenkins.Harness.SYSTEM_MONO }, }; - var buildiOSMSBuild = new MSBuildTask (jenkins: jenkins, testProject: msbuildTasksTestsProject, processManager: processManager) { + var buildiOSMSBuild = new MSBuildTask (jenkins: jenkins, testProject: netstandard2Project, processManager: processManager) { SpecifyPlatform = false, + SpecifyConfiguration = true, ProjectConfiguration = "Debug", - Platform = TestPlatform.All, - Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Msbuild), + Platform = TestPlatform.iOS, + SolutionPath = Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "..", "msbuild", "Xamarin.MacDev.Tasks.sln")), SupportsParallelExecution = false, + Environment = env, }; - var nunitExecutioniOSMSBuild = new DotNetTestTask (jenkins, buildiOSMSBuild, processManager) { - TestProject = msbuildTasksTestsProject, + var nunitExecutioniOSMSBuild = new NUnitExecuteTask (jenkins, buildiOSMSBuild, processManager) { + TestLibrary = Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tasks.Tests", "bin", "Debug", "net472", "Xamarin.MacDev.Tasks.Tests.dll"), + TestProject = netstandard2Project, ProjectConfiguration = "Debug", - Platform = TestPlatform.All, + Platform = TestPlatform.iOS, TestName = "MSBuild tests", Mode = "Tasks", Timeout = TimeSpan.FromMinutes (60), @@ -50,15 +53,18 @@ namespace Xharness.Jenkins { }; var buildiOSMSBuildIntegration = new MSBuildTask (jenkins: jenkins, testProject: msbuildIntegrationTestsProject, processManager: processManager) { SpecifyPlatform = false, + SpecifyConfiguration = true, ProjectConfiguration = "Debug", - Platform = TestPlatform.All, - Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Msbuild), + Platform = TestPlatform.iOS, + SolutionPath = Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "..", "msbuild", "Xamarin.MacDev.Tasks.sln")), SupportsParallelExecution = false, + Environment = env, }; - var nunitExecutioniOSMSBuildIntegration = new DotNetTestTask (jenkins, buildiOSMSBuildIntegration, processManager) { + var nunitExecutioniOSMSBuildIntegration = new NUnitExecuteTask (jenkins, buildiOSMSBuildIntegration, processManager) { + TestLibrary = Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tests", "bin", "Debug", "net472", "Xamarin.MacDev.Tests.dll"), TestProject = msbuildIntegrationTestsProject, ProjectConfiguration = "Debug", - Platform = TestPlatform.All, + Platform = TestPlatform.iOS, TestName = "MSBuild tests", Mode = "Integration", Timeout = TimeSpan.FromMinutes (120),