[MPP] Fix NewMultiplatformIT and make it run on arm macOS

^KT-58822
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt
index 8fdd5db..b7613ff 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt
@@ -830,6 +830,14 @@
     fun CompiledProject.assertTestResults(
         @TestDataFile assertionFileName: String,
         vararg testReportNames: String
+    ) = assertTestResults(
+        resourcesRootFile.resolve(assertionFileName),
+        *testReportNames
+    )
+
+    fun CompiledProject.assertTestResults(
+        assertionXmlFile: File,
+        vararg testReportNames: String
     ) {
         val projectDir = project.projectDir
         val testReportDirs = testReportNames.map { projectDir.resolve("build/test-results/$it").toPath() }
@@ -844,7 +852,7 @@
             val excl = "Invalid connection: com.apple.coresymbolicationd"
             s.lines().filter { it != excl }.joinToString("\n")
         }
-        val expectedTestResults = prettyPrintXml(resourcesRootFile.resolve(assertionFileName).readText())
+        val expectedTestResults = prettyPrintXml(assertionXmlFile.readText())
 
         assertEquals(expectedTestResults, actualTestResults)
     }
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt
index 993beea..ad300fb 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt
@@ -22,11 +22,10 @@
 import org.jetbrains.kotlin.gradle.plugin.sources.METADATA_CONFIGURATION_NAME_SUFFIX
 import org.jetbrains.kotlin.gradle.plugin.sources.UnsatisfiedSourceSetVisibilityException
 import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
-import org.jetbrains.kotlin.gradle.testbase.TestVersions
-import org.jetbrains.kotlin.gradle.testbase.assertHasDiagnostic
-import org.jetbrains.kotlin.gradle.testbase.assertNoDiagnostic
+import org.jetbrains.kotlin.gradle.testbase.*
 import org.jetbrains.kotlin.gradle.util.*
 import org.jetbrains.kotlin.konan.target.HostManager
+import org.jetbrains.kotlin.konan.target.KonanTarget
 import org.jetbrains.kotlin.library.KLIB_PROPERTY_SHORT_NAME
 import org.jetbrains.kotlin.library.KLIB_PROPERTY_UNIQUE_NAME
 import org.junit.Assert
@@ -688,6 +687,14 @@
             }
         }
 
+    private val targetName = when (HostManager.host) {
+        KonanTarget.LINUX_X64 -> "linux64"
+        KonanTarget.MACOS_X64 -> "macos64"
+        KonanTarget.MACOS_ARM64 -> "macosArm64"
+        KonanTarget.MINGW_X64 -> "mingw64"
+        else -> fail("Unsupported host")
+    }
+
     @Test
     fun testLibWithTests() = doTestLibWithTests(transformNativeTestProject("new-mpp-lib-with-tests", gradleVersion))
 
@@ -737,7 +744,6 @@
                     arrayOf(
                         it + "com/example/lib/CommonKt.class",
                         it + "com/example/lib/MainKt.class",
-                        it + "Script.class",
                         it + "META-INF/new-mpp-lib-with-tests.kotlin_module"
                     )
                 },
@@ -751,22 +757,15 @@
             )
 
             expectedKotlinOutputFiles.forEach { assertFileExists(it) }
+            val expectedTestResults = projectDir.resolve("TEST-all.xml")
 
-            // Gradle 6.6+ slightly changed format of xml test results
-            // If, in the test project, preset name was updated,
-            // update accordingly test result output for Gradle 6.6+
-            val testGradleVersion = chooseWrapperVersionOrFinishTest()
-            val expectedTestResults = if (GradleVersion.version(testGradleVersion) < GradleVersion.version("6.6")) {
-                "testProject/new-mpp-lib-with-tests/TEST-all-pre6.6.xml"
-            } else {
-                "testProject/new-mpp-lib-with-tests/TEST-all.xml"
-            }
+            expectedTestResults.replaceText("<target>", targetName)
 
             assertTestResults(
                 expectedTestResults,
                 "jsNodeTest",
                 "test", // jvmTest
-                "${nativeHostTargetName}Test"
+                "${targetName}Test"
             )
         }
     }
@@ -1796,7 +1795,11 @@
         gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
 
         // TOOD: add Kotlin/JS tests once they can be tested without much performance overhead
-        val targetsToTest = listOf("jvm", nativeHostTargetName) + listOf("ios").takeIf { HostManager.hostIsMac }.orEmpty()
+        val targetsToTest = listOf("jvm", nativeHostTargetName) + when (HostManager.host) {
+            KonanTarget.MACOS_X64 -> listOf("iosX64")
+            KonanTarget.MACOS_ARM64 -> listOf("iosSimulatorArm64")
+            else -> emptyList()
+        }
         val testTasks = targetsToTest.flatMap { listOf(":${it}Test", ":${it}IntegrationTest") }.toTypedArray()
 
         build(*testTasks) {
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt
index b7c7c7f..9bec312 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt
@@ -30,11 +30,12 @@
 import kotlin.test.assertTrue
 
 internal object MPPNativeTargets {
-    val current = when {
-        HostManager.hostIsMingw -> "mingw64"
-        HostManager.hostIsLinux -> "linux64"
-        HostManager.hostIsMac -> "macos64"
-        else -> error("Unknown host")
+    val current = when (HostManager.host) {
+        KonanTarget.LINUX_X64 -> "linux64"
+        KonanTarget.MACOS_X64 -> "macos64"
+        KonanTarget.MACOS_ARM64 -> "macosArm64"
+        KonanTarget.MINGW_X64 -> "mingw64"
+        else -> error("Unsupported host")
     }
 
     val unsupported = when {
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-associate-compilations/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-associate-compilations/build.gradle
index 86bc6a6..d4cb4b6 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-associate-compilations/build.gradle
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-associate-compilations/build.gradle
@@ -49,7 +49,9 @@
     mingwX64("mingw64") {}
     linuxX64("linux64") {}
     macosX64("macos64") {}
-    iosX64("ios") {}
+    macosArm64("macosArm64") {}
+    iosX64("iosX64") {}
+    iosSimulatorArm64("iosSimulatorArm64") {}
 
     targets.matching { it.name != "metadata" }.all {
         compilations.create("integrationTest") {
@@ -90,7 +92,7 @@
         }
     }
 
-    targets.matching { it.name == "mingw64" || it.name == "linux64" || it.name == "macos64" || it.name == "ios" }.all {
+    targets.matching { it.name == "mingw64" || it.name == "linux64" || it.name == "macos64" || it.name == "macosArm64" || it.name == "iosX64" || it.name == "iosSimulatorArm64" }.all {
         testRuns {
             getByName("test").filter { excludeTestsMatching("*.secondTest") }
 
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/TEST-all-pre6.6.xml b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/TEST-all-pre6.6.xml
deleted file mode 100644
index 1d5e0d7..0000000
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/TEST-all-pre6.6.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<results>
-  <testsuite name="com.example.lib.TestCommonCode" tests="2" skipped="0" failures="0" errors="0" timestamp="..." hostname="..." time="...">
-    <properties />
-    <testcase name="testId" classname="com.example.lib.TestCommonCode" time="..." />
-    <testcase name="testExpectedFun" classname="com.example.lib.TestCommonCode" time="..." />
-    <system-out />
-    <system-err />
-  </testsuite>
-  <testsuite name="com.example.lib.TestCommonCode" tests="2" skipped="0" failures="0" errors="0" timestamp="..." hostname="..." time="...">
-    <properties />
-    <testcase name="testId" classname="com.example.lib.TestCommonCode" time="..." />
-    <testcase name="testExpectedFun" classname="com.example.lib.TestCommonCode" time="..." />
-    <system-out><![CDATA[1]]></system-out>
-    <system-err />
-  </testsuite>
-  <testsuite name="com.example.lib.TestCommonCode" tests="2" skipped="0" failures="0" errors="0" timestamp="..." hostname="..." time="...">
-    <properties />
-    <testcase name="testId" classname="com.example.lib.TestCommonCode" time="..." />
-    <testcase name="testExpectedFun" classname="com.example.lib.TestCommonCode" time="..." />
-    <system-out />
-    <system-err />
-  </testsuite>
-  <testsuite name="com.example.lib.TestJava" tests="1" skipped="0" failures="0" errors="0" timestamp="..." hostname="..." time="...">
-    <properties />
-    <testcase name="testJava" classname="com.example.lib.TestJava" time="..." />
-    <system-out />
-    <system-err />
-  </testsuite>
-  <testsuite name="com.example.lib.TestJs" tests="1" skipped="0" failures="0" errors="0" timestamp="..." hostname="..." time="...">
-    <properties />
-    <testcase name="testJsSpecificCode" classname="com.example.lib.TestJs" time="..." />
-    <system-out />
-    <system-err />
-  </testsuite>
-  <testsuite name="com.example.lib.TestWithJava" tests="1" skipped="0" failures="0" errors="0" timestamp="..." hostname="..." time="...">
-    <properties />
-    <testcase name="testJavaClass" classname="com.example.lib.TestWithJava" time="..." />
-    <system-out />
-    <system-err />
-  </testsuite>
-</results>
-
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/TEST-all.xml b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/TEST-all.xml
index 5962d0a..34c8658 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/TEST-all.xml
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/TEST-all.xml
@@ -16,8 +16,8 @@
   </testsuite>
   <testsuite name="com.example.lib.TestCommonCode" tests="2" skipped="0" failures="0" errors="0" timestamp="..." hostname="..." time="...">
     <properties />
-    <testcase name="testId[linux64]" classname="com.example.lib.TestCommonCode" time="..." />
-    <testcase name="testExpectedFun[linux64]" classname="com.example.lib.TestCommonCode" time="..." />
+    <testcase name="testId[<target>]" classname="com.example.lib.TestCommonCode" time="..." />
+    <testcase name="testExpectedFun[<target>]" classname="com.example.lib.TestCommonCode" time="..." />
     <system-out />
     <system-err />
   </testsuite>
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle
index ea5e79a..5ca51a7 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle
@@ -23,6 +23,7 @@
     	fromPreset(presets.jvm, 'jvmWithoutJava')
         fromPreset(presets.jvmWithJava, 'jvmWithJava')
 		fromPreset(presets.macosX64, 'macos64')
+		fromPreset(presets.macosArm64, 'macosArm64')
 		fromPreset(presets.linuxX64, 'linux64')
 		fromPreset(presets.mingwX64, 'mingw64')
     }
@@ -56,7 +57,7 @@
         	}
         }
 		nativeMain
-		configure([macos64Main, linux64Main, mingw64Main]) {
+		configure([macos64Main, macosArm64Main, linux64Main, mingw64Main]) {
 			dependsOn nativeMain
 		}
     }
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle.kts.alternative b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle.kts.alternative
index f0be6e1..bf27bc5 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle.kts.alternative
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle.kts.alternative
@@ -14,6 +14,7 @@
         nodejs()
     }
     val macos64 = macosX64("macos64")
+    val macosArm64 = macosArm64("macosArm64")
     val linux64 = linuxX64("linux64")
     val mingw64 = mingwX64("mingw64")
 
@@ -49,7 +50,7 @@
         }
 
 		val nativeMain by creating
-		configure(listOf(macos64, linux64, mingw64)) {
+		configure(listOf(macos64, macosArm64, linux64, mingw64)) {
             compilations["main"].defaultSourceSet.dependsOn(nativeMain)
 		}
     }
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/src/jvmWithoutJavaMain/kotlin/script.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/src/jvmWithoutJavaMain/kotlin/script.kts
deleted file mode 100644
index 837db87..0000000
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/src/jvmWithoutJavaMain/kotlin/script.kts
+++ /dev/null
@@ -1,2 +0,0 @@
-
-val x = 0