From 419994785460ba6632ac35ea08a32b79b7fbc405 Mon Sep 17 00:00:00 2001 From: Tadeas Kriz Date: Thu, 11 Apr 2024 23:35:44 -0400 Subject: [PATCH] Split Gradle tests to separate files for parallel running. --- .../skie/test/base/BaseGradleTests.kt | 17 +- .../KotlinArtifactDsl_Framework_Tests.kt | 137 ------- .../KotlinArtifactDsl_XCFramework_Tests.kt | 355 ------------------ .../basic/BasicGradle_AllDarwinPresets.kt | 79 ---- ...DarwinTargetsAllFrameworkArtifactsTests.kt | 54 +++ ...rwinTargetsSingleFrameworkArtifactTests.kt | 54 +++ ...ArtifactDsl_Framework_SingleTargetTests.kt | 50 +++ ...ctDsl_XCFramework_AllDarwinTargetsTests.kt | 63 ++++ ...tifactDsl_XCFramework_SingleTargetTests.kt | 65 ++++ ...naryDsl_Framework_AllDarwinPresetsTests.kt | 39 ++ ...nBinaryDsl_Framework_SinglePresetTests.kt} | 4 +- ...nBinaryDsl_Framework_SingleTargetTests.kt} | 4 +- .../NoArtifact_AllDarwinTargetsTests.kt} | 6 +- .../basic/NoArtifact_SingleTargetTests.kt | 28 ++ .../test/trait/gradle/BuildGradleBuilder.kt | 145 ++++--- .../test/util/BuildResult.shouldBeSuccess.kt | 9 + .../test/util/BuildTask.shouldBeSuccess.kt | 11 + .../test/resources/junit-platform.properties | 14 +- 18 files changed, 497 insertions(+), 637 deletions(-) delete mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_Framework_Tests.kt delete mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_XCFramework_Tests.kt delete mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_AllDarwinPresets.kt create mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_AllDarwinTargetsAllFrameworkArtifactsTests.kt create mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_AllDarwinTargetsSingleFrameworkArtifactTests.kt create mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_SingleTargetTests.kt create mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_XCFramework_AllDarwinTargetsTests.kt create mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_XCFramework_SingleTargetTests.kt create mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_AllDarwinPresetsTests.kt rename test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/{BasicGradle_SinglePreset.kt => KotlinBinaryDsl_Framework_SinglePresetTests.kt} (85%) rename test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/{BasicGradle_SingleTarget.kt => KotlinBinaryDsl_Framework_SingleTargetTests.kt} (85%) rename test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/{artifact/KotlinArtifactDsl_NoArtifact_Tests.kt => basic/NoArtifact_AllDarwinTargetsTests.kt} (77%) create mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/NoArtifact_SingleTargetTests.kt create mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/util/BuildResult.shouldBeSuccess.kt create mode 100644 test-runner/src/test/kotlin/co/touchlab/skie/test/util/BuildTask.shouldBeSuccess.kt diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/base/BaseGradleTests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/base/BaseGradleTests.kt index 5d75a14e..c20ab44e 100644 --- a/test-runner/src/test/kotlin/co/touchlab/skie/test/base/BaseGradleTests.kt +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/base/BaseGradleTests.kt @@ -86,8 +86,7 @@ abstract class BaseGradleTests: TestUtilsTrait, GradleBuildFileBuilderTrait { fun buildSwift( target: KotlinTarget.Native.Darwin, template: Template, - configuration: BuildConfiguration, - frameworkParentPath: String = "build/bin/${target.id}/${configuration.name.lowercase()}Framework", + frameworkParentPath: String, assertResult: ((CommandResult) -> Unit)? = { assertEquals(0, it.exitCode) }, @@ -115,7 +114,7 @@ abstract class BaseGradleTests: TestUtilsTrait, GradleBuildFileBuilderTrait { } fun runSwift() { - + // TODO: Implement running binaries } fun commonMain(fqdn: String): File { @@ -133,4 +132,16 @@ abstract class BaseGradleTests: TestUtilsTrait, GradleBuildFileBuilderTrait { file.file.copyTo(targetFile) } } + + fun builtFrameworkParentDir( + target: KotlinTarget.Native.Darwin, + configuration: BuildConfiguration, + isArtifactDsl: Boolean, + ): String { + return if (isArtifactDsl) { + "build/out/framework/${target.frameworkTarget}/${configuration.name.lowercase()}" + } else { + "build/bin/${target.id}/${configuration.name.lowercase()}Framework" + } + } } diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_Framework_Tests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_Framework_Tests.kt deleted file mode 100644 index bf6cdbb8..00000000 --- a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_Framework_Tests.kt +++ /dev/null @@ -1,137 +0,0 @@ -package co.touchlab.skie.test.suite.gradle.artifact - -import co.touchlab.skie.test.* -import co.touchlab.skie.test.annotation.MatrixTest -import co.touchlab.skie.test.annotation.filter.OnlyDebug -import co.touchlab.skie.test.annotation.filter.OnlyDynamic -import co.touchlab.skie.test.annotation.filter.OnlyFor -import co.touchlab.skie.test.annotation.filter.Smoke -import co.touchlab.skie.test.annotation.type.GradleTests -import co.touchlab.skie.test.base.BaseGradleTests -import co.touchlab.skie.test.runner.BuildConfiguration -import co.touchlab.skie.test.template.Templates -import co.touchlab.skie.test.util.KotlinTarget -import co.touchlab.skie.test.util.KotlinVersion -import co.touchlab.skie.test.util.LinkMode -import co.touchlab.skie.test.util.RawKotlinTarget - -@OnlyFor( - targets = [RawKotlinTarget.iosSimulatorArm64], -) -@OnlyDebug -@OnlyDynamic -@Suppress("ClassName") -@Smoke -@GradleTests -class KotlinArtifactDsl_Framework_Tests: BaseGradleTests() { - - @MatrixTest - fun `single target and single framework artifact`( - kotlinVersion: KotlinVersion, - target: KotlinTarget.Native.Darwin, - linkMode: LinkMode, - configuration: BuildConfiguration, - ) { - rootBuildFile(kotlinVersion) { - kotlin { - target(target) - } - - +""" - kotlinArtifacts { - Native.Framework { - target = ${target.id} - modes(${configuration.toString().uppercase()}) - isStatic = ${linkMode.isStatic} - } - } - """.trimIndent() - } - - copyToCommonMain(Templates.basic) - - runGradle() - - buildSwift(target, Templates.basic, configuration) - - if (target is KotlinTarget.Native.MacOS) { - runSwift() - } - } - - @MatrixTest - fun `all darwin targets and single framework artifact`( - kotlinVersion: KotlinVersion, - target: KotlinTarget.Native.Darwin, - linkMode: LinkMode, - configuration: BuildConfiguration, - ) { - rootBuildFile(kotlinVersion) { - kotlin { - allDarwin() - } - - +""" - kotlinArtifacts { - Native.Framework { - target = ${target.id} - modes(${configuration.toString().uppercase()}) - isStatic = ${linkMode.isStatic} - } - } - """.trimIndent() - } - - copyToCommonMain(Templates.basic) - - runGradle() - - buildSwift( - target = target, - frameworkParentPath = "build/out/framework/ios_simulator_arm64/debug", - template = Templates.basic, - configuration = configuration, - ) - - if (target is KotlinTarget.Native.MacOS) { - runSwift() - } - } - - @MatrixTest - fun `all darwin targets and all framework artifacts`( - kotlinVersion: KotlinVersion, - linkMode: LinkMode, - configuration: BuildConfiguration, - ) { - rootBuildFile(kotlinVersion) { - kotlin { - allDarwin() - } - - +"kotlinArtifacts {" - KotlinTarget.Native.Darwin.targets.forEach { target -> - +""" - | Native.Framework { - | target = ${target.id} - | modes(${configuration.toString().uppercase()}) - | isStatic = ${linkMode.isStatic} - | } - """.trimMargin() - } - +"}" - } - - copyToCommonMain(Templates.basic) - - runGradle() - - KotlinTarget.Native.Darwin.targets.forEach { target -> - buildSwift(target, Templates.basic, configuration) - - if (target is KotlinTarget.Native.MacOS) { - runSwift() - } - } - } -} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_XCFramework_Tests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_XCFramework_Tests.kt deleted file mode 100644 index 47000e5d..00000000 --- a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_XCFramework_Tests.kt +++ /dev/null @@ -1,355 +0,0 @@ -package co.touchlab.skie.test.suite.gradle.artifact - -import co.touchlab.skie.test.* -import co.touchlab.skie.test.annotation.MatrixTest -import co.touchlab.skie.test.annotation.filter.OnlyDebug -import co.touchlab.skie.test.annotation.filter.OnlyDynamic -import co.touchlab.skie.test.annotation.filter.OnlyFor -import co.touchlab.skie.test.annotation.filter.Smoke -import co.touchlab.skie.test.annotation.type.GradleTests -import co.touchlab.skie.test.base.BaseGradleTests -import co.touchlab.skie.test.runner.BuildConfiguration -import co.touchlab.skie.test.runner.SkieTestRunnerConfiguration -import co.touchlab.skie.test.template.Template -import co.touchlab.skie.test.template.TemplateFile -import co.touchlab.skie.test.template.Templates -import co.touchlab.skie.test.trait.TestUtilsTrait -import co.touchlab.skie.test.trait.gradle.BuildGradleFile -import co.touchlab.skie.test.trait.gradle.GradleBuildFileBuilderTrait -import co.touchlab.skie.test.util.* -import io.kotest.core.spec.DslDrivenSpec -import io.kotest.core.spec.style.funSpec -import io.kotest.core.spec.style.scopes.ContainerScope -import io.kotest.core.spec.style.scopes.FunSpecRootScope -import io.kotest.datatest.withData -import io.kotest.engine.spec.tempdir -import org.gradle.testkit.runner.BuildResult -import org.gradle.testkit.runner.GradleRunner -import org.gradle.testkit.runner.TaskOutcome -import org.junit.jupiter.api.BeforeEach -import java.io.File -import kotlin.test.assertEquals - -fun xcFrameworkTests( - kotlinVersion: KotlinVersion, - target: KotlinTarget.Native.Darwin, - linkMode: LinkMode, - configuration: BuildConfiguration -) = funSpec { - -} - -class KotlinArtifactDsl_XCFramework_Spec: BaseSpec({ - context("test context") { - withMatrix { kotlinVersion: KotlinVersion, target: KotlinTarget.Native.Darwin, linkMode: LinkMode, configuration: BuildConfiguration -> - rootBuildFile(kotlinVersion) { - kotlin { - target(target) - } - - +""" - kotlinArtifacts { - Native.XCFramework { - targets(${target.id}) - modes(${configuration.toString().uppercase()}) - isStatic = ${linkMode.isStatic} - } - } - """.trimIndent() - } - - copyToCommonMain(Templates.basic) - - runGradle() - - buildSwift(target, Templates.basic) - - if (target is KotlinTarget.Native.MacOS) { - runSwift() - } - } - } -}) - -abstract class BaseSpec(body: BaseSpec.() -> Unit): DslDrivenSpec(), FunSpecRootScope, TestUtilsTrait, GradleBuildFileBuilderTrait { - init { - beforeTest { - createSettingsFile() - createGradlePropertiesFile() - } - body() - } - - suspend inline fun ContainerScope.withMatrix(crossinline test: suspend ContainerScope.(p1: P1) -> Unit) { - withData(matrixAxis()) { p1 -> - test(p1) - } - } - suspend inline fun ContainerScope.withMatrix(crossinline test: suspend ContainerScope.(p1: P1, p2: P2) -> Unit) { - withMatrix { p1 -> - withData(matrixAxis()) { p2 -> - test(p1, p2) - } - } - } - - suspend inline fun ContainerScope.withMatrix(crossinline test: suspend ContainerScope.(p1: P1, p2: P2, p3: P3) -> Unit) { - withMatrix { p1, p2 -> - withData(matrixAxis()) { p3 -> - test(p1, p2, p3) - } - } - } - - suspend inline fun ContainerScope.withMatrix(crossinline test: suspend ContainerScope.(p1: P1, p2: P2, p3: P3, p4: P4) -> Unit) { - withMatrix { p1, p2, p3 -> - withData(matrixAxis()) { p4 -> - test(p1, p2, p3, p4) - } - } - } - - @PublishedApi - internal inline fun matrixAxis(): List { - TODO() - } - - suspend fun ContainerScope.withKotlinVersion(test: suspend ContainerScope.(KotlinVersion) -> Unit) { - withData( - nameFn = { it.value }, - ts = SkieTestRunnerConfiguration.kotlinVersions, - test = test, - ) - } - - suspend fun ContainerScope.withTarget(test: suspend ContainerScope.(KotlinTarget) -> Unit) { - withData( - ts = SkieTestRunnerConfiguration.targets.targets, - test = test, - ) - } - - suspend fun ContainerScope.withDarwinTarget(test: suspend ContainerScope.(KotlinTarget.Native.Darwin) -> Unit) { - withData( - ts = SkieTestRunnerConfiguration.targets.targets.filterIsInstance(), - test = test - ) - } - - suspend fun ContainerScope.withLinkMode(test: suspend ContainerScope.(LinkMode) -> Unit) { - withData( - ts = SkieTestRunnerConfiguration.linkModes, - test = test, - ) - } - - suspend fun ContainerScope.withConfiguration(test: ContainerScope.(BuildConfiguration) -> Unit) { - withData( - ts = SkieTestRunnerConfiguration.configurations, - test = test, - ) - } - -// @TempDir(cleanup = CleanupMode.ON_SUCCESS) - var testProjectDir: File = tempdir() - - val settingsFile: File - get() = File(testProjectDir, "settings.gradle.kts") - val rootBuildFile: BuildGradleFile - get() = BuildGradleFile(File(testProjectDir, "build.gradle.kts")) - val gradlePropertiesFile: File - get() = File(testProjectDir, "gradle.properties") - - @BeforeEach - fun createSettingsFile() { - this.settingsFile.invoke(""" - pluginManagement { - repositories { - maven("${tempRepository.absolutePath}") - gradlePluginPortal() - } - } - - rootProject.name = "gradle-test" - - dependencyResolutionManagement { - repositories { - maven("${tempRepository.absolutePath}") - mavenCentral() - google() - } - } - """.trimIndent()) - } - - @BeforeEach - fun createGradlePropertiesFile() { - gradlePropertiesFile(""" - org.gradle.jvmargs=-XX:+UseParallelGC - """.trimIndent()) - } - - fun runGradle( - gradleVersion: String = "8.4", - vararg arguments: String = arrayOf("build"), - assertResult: ((BuildResult) -> Unit)? = { - assertEquals(TaskOutcome.SUCCESS, it.task(":build")?.outcome) - }, - ): BuildResult { - val result: BuildResult = GradleRunner.create() - .withProjectDir(testProjectDir) - .withGradleVersion(gradleVersion) - .withArguments(*arguments) - .forwardOutput() -// .withDebug(true) - .build() - - assertResult?.invoke(result) - - return result - } - - fun buildSwift( - target: KotlinTarget.Native.Darwin, - template: Template, - frameworkParentPath: String = "build/out/framework/ios_simulator_arm64/debug", - assertResult: ((CommandResult) -> Unit)? = { - assertEquals(0, it.exitCode) - }, - ): CommandResult { - val command = buildList { - this += "/usr/bin/xcrun" - this += listOf("-sdk", target.sdk) - this += "swiftc" - this += template.files.filter { it.kind == TemplateFile.Kind.Swift }.map { it.file.absolutePath } - this += listOf("-F", frameworkParentPath) - this += listOf("-o", "swift_executable") - this += listOf("-target", target.triple) - // Workaround for https://github.com/apple/swift/issues/55127 - this += "-parse-as-library" - // Workaround for missing symbol when compiling with Coroutines for MacosArm64 - this += listOf("-Xlinker", "-dead_strip") - } - - val result = command.joinToString(" ").execute(testProjectDir) - println(result.stdOut) - - assertResult?.invoke(result) - - return result - } - - fun runSwift() { - - } - - fun commonMain(fqdn: String): File { - return testProjectDir.resolve("src/commonMain/kotlin").resolve(fqdn.split(".").joinToString("/") + ".kt").also { - it.parentFile.mkdirs() - } - } - - fun copyToCommonMain(template: Template) { - template.files.forEach { file -> - val targetFile = testProjectDir - .resolve("src/commonMain/kotlin") - .resolve(file.relativePath) - targetFile.parentFile.mkdirs() - file.file.copyTo(targetFile) - } - } -} - - -@OnlyFor( - targets = [RawKotlinTarget.iosSimulatorArm64], -) -@OnlyDebug -@OnlyDynamic -@Suppress("ClassName") -@Smoke -@GradleTests -class KotlinArtifactDsl_XCFramework_Tests: BaseGradleTests() { - - @MatrixTest - fun `single target`( - kotlinVersion: KotlinVersion, - target: KotlinTarget.Native.Darwin, - linkMode: LinkMode, - configuration: BuildConfiguration, - ) { - rootBuildFile(kotlinVersion) { - kotlin { - target(target) - } - - +""" - kotlinArtifacts { - Native.XCFramework { - targets(${target.id}) - modes(${configuration.toString().uppercase()}) - isStatic = ${linkMode.isStatic} - } - } - """.trimIndent() - } - - copyToCommonMain(Templates.basic) - - runGradle() - - buildSwift(target, Templates.basic, configuration) - - if (target is KotlinTarget.Native.MacOS) { - runSwift() - } - } - - @MatrixTest - fun `all darwin targets and single xcframework artifact`( - kotlinVersion: KotlinVersion, - linkMode: LinkMode, - configuration: BuildConfiguration, - ) { - rootBuildFile(kotlinVersion) { - kotlin { - allDarwin() - } - - +""" - kotlinArtifacts { - Native.XCFramework { - targets(${KotlinTarget.Native.Darwin.targets.joinToString { it.id }}) - modes(${configuration.toString().uppercase()}) - isStatic = ${linkMode.isStatic} - } - } - """.trimIndent() - } - - copyToCommonMain(Templates.basic) - - runGradle() - - KotlinTarget.Native.Darwin.targets.forEach { target -> - val frameworkParentName = when (target) { - KotlinTarget.Native.Ios.SimulatorArm64, KotlinTarget.Native.Ios.X64 -> "ios-arm64_x86_64-simulator" - KotlinTarget.Native.Ios.Arm64 -> "ios-arm64" - KotlinTarget.Native.Tvos.SimulatorArm64, KotlinTarget.Native.Tvos.X64 -> "tvos-arm64_x86_64-simulator" - KotlinTarget.Native.Tvos.Arm64 -> "tvos-arm64" - KotlinTarget.Native.MacOS.Arm64, KotlinTarget.Native.MacOS.X64 -> "macos-arm64_x86_64" - } - - buildSwift( - target = target, - frameworkParentPath = "build/out/xcframework/${configuration.name.lowercase()}/gradle_test.xcframework/$frameworkParentName", - template = Templates.basic, - configuration = configuration, - ) - - if (target is KotlinTarget.Native.MacOS) { - runSwift() - } - } - } -} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_AllDarwinPresets.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_AllDarwinPresets.kt deleted file mode 100644 index 7eb2debe..00000000 --- a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_AllDarwinPresets.kt +++ /dev/null @@ -1,79 +0,0 @@ -package co.touchlab.skie.test.suite.gradle.basic - -import co.touchlab.skie.test.annotation.MatrixTest -import co.touchlab.skie.test.annotation.filter.Smoke -import co.touchlab.skie.test.annotation.type.GradleTests -import co.touchlab.skie.test.base.BaseGradleTests -import co.touchlab.skie.test.runner.BuildConfiguration -import co.touchlab.skie.test.runner.SkieTestRunnerConfiguration -import co.touchlab.skie.test.template.Templates -import co.touchlab.skie.test.util.KotlinTarget -import co.touchlab.skie.test.util.KotlinVersion -import co.touchlab.skie.test.util.LinkMode -import io.kotest.matchers.collections.shouldBeEmpty -import io.kotest.matchers.nulls.shouldNotBeNull -import io.kotest.matchers.shouldBe -import io.kotest.property.exhaustive.exhaustive -import org.gradle.testkit.runner.BuildResult -import org.gradle.testkit.runner.BuildTask -import org.gradle.testkit.runner.TaskOutcome - -object Properties { - val kotlinVersions = SkieTestRunnerConfiguration.kotlinVersions.exhaustive() -} - -fun BuildTask?.shouldBeSuccess() { - this.shouldNotBeNull() - .outcome shouldBe TaskOutcome.SUCCESS -} - -fun BuildResult.shouldBeSuccess() { - this.tasks(TaskOutcome.FAILED).shouldBeEmpty() -} - -interface ParallelDynamicTest { - fun beforeEach() {} - - fun afterEach() {} -} - -// object Source_BasicGradleTests { -// fun `empty project`(kotlinVersion: KotlinVersion) { -// tempTestDir.createFile(...).appendText(...) -// } -// } -// -// class Kotlin1_8_0_BasicGradleTests_empty_project { -// @Test -// fun doTest() { -// Source_BasicGradleTests.`empty project`(KotlinVersion("1.8.0")) -// } -// } - -@Suppress("ClassName") -@GradleTests -class BasicGradle_AllDarwinPresets: BaseGradleTests() { - @Smoke - @MatrixTest - fun `basic project, all darwin presets`( - kotlinVersion: KotlinVersion, - buildConfiguration: BuildConfiguration, - linkMode: LinkMode, - ) { - rootBuildFile(kotlinVersion) { - kotlin { - targets(KotlinTarget.Native.Darwin) - - registerNativeFrameworks(kotlinVersion, buildConfiguration, linkMode) - } - } - - copyToCommonMain(Templates.basic) - - runGradle() - - KotlinTarget.Native.Darwin.targets.forEach { target -> - buildSwift(target, Templates.basic, buildConfiguration) - } - } -} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_AllDarwinTargetsAllFrameworkArtifactsTests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_AllDarwinTargetsAllFrameworkArtifactsTests.kt new file mode 100644 index 00000000..e6501155 --- /dev/null +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_AllDarwinTargetsAllFrameworkArtifactsTests.kt @@ -0,0 +1,54 @@ +package co.touchlab.skie.test.suite.gradle.basic + +import co.touchlab.skie.test.annotation.MatrixTest +import co.touchlab.skie.test.annotation.filter.Smoke +import co.touchlab.skie.test.annotation.type.GradleTests +import co.touchlab.skie.test.base.BaseGradleTests +import co.touchlab.skie.test.runner.BuildConfiguration +import co.touchlab.skie.test.template.Templates +import co.touchlab.skie.test.util.KotlinTarget +import co.touchlab.skie.test.util.KotlinVersion +import co.touchlab.skie.test.util.LinkMode + + +@Suppress("ClassName") +@Smoke +@GradleTests +class KotlinArtifactDsl_Framework_AllDarwinTargetsAllFrameworkArtifactsTests: BaseGradleTests() { + + @MatrixTest + fun `all darwin targets and all framework artifacts`( + kotlinVersion: KotlinVersion, + linkMode: LinkMode, + configuration: BuildConfiguration, + ) { + rootBuildFile(kotlinVersion) { + kotlin { + allDarwin() + } + + kotlinArtifacts { + KotlinTarget.Native.Darwin.targets.forEach { target -> + framework( + kotlinVersion = kotlinVersion, + target = target, + linkMode = linkMode, + buildConfiguration = configuration, + ) + } + } + } + + copyToCommonMain(Templates.basic) + + runGradle() + + KotlinTarget.Native.Darwin.targets.forEach { target -> + buildSwift(target, Templates.basic, builtFrameworkParentDir(target, configuration, isArtifactDsl = true)) + + if (target is KotlinTarget.Native.MacOS) { + runSwift() + } + } + } +} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_AllDarwinTargetsSingleFrameworkArtifactTests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_AllDarwinTargetsSingleFrameworkArtifactTests.kt new file mode 100644 index 00000000..17143bb8 --- /dev/null +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_AllDarwinTargetsSingleFrameworkArtifactTests.kt @@ -0,0 +1,54 @@ +package co.touchlab.skie.test.suite.gradle.basic + +import co.touchlab.skie.test.annotation.MatrixTest +import co.touchlab.skie.test.annotation.filter.Smoke +import co.touchlab.skie.test.annotation.type.GradleTests +import co.touchlab.skie.test.base.BaseGradleTests +import co.touchlab.skie.test.runner.BuildConfiguration +import co.touchlab.skie.test.template.Templates +import co.touchlab.skie.test.util.KotlinTarget +import co.touchlab.skie.test.util.KotlinVersion +import co.touchlab.skie.test.util.LinkMode + +@Suppress("ClassName") +@Smoke +@GradleTests +class KotlinArtifactDsl_Framework_AllDarwinTargetsSingleFrameworkArtifactTests: BaseGradleTests() { + + @MatrixTest + fun `all darwin targets and single framework artifact`( + kotlinVersion: KotlinVersion, + target: KotlinTarget.Native.Darwin, + linkMode: LinkMode, + configuration: BuildConfiguration, + ) { + rootBuildFile(kotlinVersion) { + kotlin { + allDarwin() + } + + kotlinArtifacts { + framework( + kotlinVersion = kotlinVersion, + target = target, + linkMode = linkMode, + buildConfiguration = configuration, + ) + } + } + + copyToCommonMain(Templates.basic) + + runGradle() + + buildSwift( + target = target, + template = Templates.basic, + frameworkParentPath = builtFrameworkParentDir(target, configuration, isArtifactDsl = true), + ) + + if (target is KotlinTarget.Native.MacOS) { + runSwift() + } + } +} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_SingleTargetTests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_SingleTargetTests.kt new file mode 100644 index 00000000..b3fcd410 --- /dev/null +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_Framework_SingleTargetTests.kt @@ -0,0 +1,50 @@ +package co.touchlab.skie.test.suite.gradle.basic + +import co.touchlab.skie.test.annotation.MatrixTest +import co.touchlab.skie.test.annotation.filter.Smoke +import co.touchlab.skie.test.annotation.type.GradleTests +import co.touchlab.skie.test.base.BaseGradleTests +import co.touchlab.skie.test.runner.BuildConfiguration +import co.touchlab.skie.test.template.Templates +import co.touchlab.skie.test.util.KotlinTarget +import co.touchlab.skie.test.util.KotlinVersion +import co.touchlab.skie.test.util.LinkMode + +@Suppress("ClassName") +@Smoke +@GradleTests +class KotlinArtifactDsl_Framework_SingleTargetTests: BaseGradleTests() { + + @MatrixTest + fun `single target and single framework artifact`( + kotlinVersion: KotlinVersion, + target: KotlinTarget.Native.Darwin, + linkMode: LinkMode, + configuration: BuildConfiguration, + ) { + rootBuildFile(kotlinVersion) { + kotlin { + target(target) + } + + kotlinArtifacts { + framework( + kotlinVersion = kotlinVersion, + target = target, + linkMode = linkMode, + buildConfiguration = configuration, + ) + } + } + + copyToCommonMain(Templates.basic) + + runGradle() + + buildSwift(target, Templates.basic, builtFrameworkParentDir(target, configuration, isArtifactDsl = true)) + + if (target is KotlinTarget.Native.MacOS) { + runSwift() + } + } +} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_XCFramework_AllDarwinTargetsTests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_XCFramework_AllDarwinTargetsTests.kt new file mode 100644 index 00000000..d6add8f1 --- /dev/null +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_XCFramework_AllDarwinTargetsTests.kt @@ -0,0 +1,63 @@ +package co.touchlab.skie.test.suite.gradle.basic + +import co.touchlab.skie.test.annotation.MatrixTest +import co.touchlab.skie.test.annotation.filter.Smoke +import co.touchlab.skie.test.annotation.type.GradleTests +import co.touchlab.skie.test.base.BaseGradleTests +import co.touchlab.skie.test.runner.BuildConfiguration +import co.touchlab.skie.test.template.Templates +import co.touchlab.skie.test.util.KotlinTarget +import co.touchlab.skie.test.util.KotlinVersion +import co.touchlab.skie.test.util.LinkMode + +@Suppress("ClassName") +@Smoke +@GradleTests +class KotlinArtifactDsl_XCFramework_AllDarwinTargetsTests: BaseGradleTests() { + + @MatrixTest + fun `all darwin targets and single xcframework artifact`( + kotlinVersion: KotlinVersion, + linkMode: LinkMode, + configuration: BuildConfiguration, + ) { + rootBuildFile(kotlinVersion) { + kotlin { + allDarwin() + } + + kotlinArtifacts { + xcframework( + kotlinVersion = kotlinVersion, + targets = KotlinTarget.Native.Darwin.targets, + linkMode = linkMode, + buildConfiguration = configuration, + ) + } + } + + copyToCommonMain(Templates.basic) + + runGradle() + + KotlinTarget.Native.Darwin.targets.forEach { target -> + val frameworkParentName = when (target) { + KotlinTarget.Native.Ios.SimulatorArm64, KotlinTarget.Native.Ios.X64 -> "ios-arm64_x86_64-simulator" + KotlinTarget.Native.Ios.Arm64 -> "ios-arm64" + KotlinTarget.Native.Tvos.SimulatorArm64, KotlinTarget.Native.Tvos.X64 -> "tvos-arm64_x86_64-simulator" + KotlinTarget.Native.Tvos.Arm64 -> "tvos-arm64" + KotlinTarget.Native.MacOS.Arm64, KotlinTarget.Native.MacOS.X64 -> "macos-arm64_x86_64" + } + + buildSwift( + target = target, + frameworkParentPath = "build/out/xcframework/${configuration.name.lowercase()}/gradle_test.xcframework/$frameworkParentName", + template = Templates.basic, + ) + + if (target is KotlinTarget.Native.MacOS) { + runSwift() + } + } + } +} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_XCFramework_SingleTargetTests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_XCFramework_SingleTargetTests.kt new file mode 100644 index 00000000..63b3f947 --- /dev/null +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinArtifactDsl_XCFramework_SingleTargetTests.kt @@ -0,0 +1,65 @@ +package co.touchlab.skie.test.suite.gradle.basic + +import co.touchlab.skie.test.annotation.MatrixTest +import co.touchlab.skie.test.annotation.filter.Smoke +import co.touchlab.skie.test.annotation.type.GradleTests +import co.touchlab.skie.test.base.BaseGradleTests +import co.touchlab.skie.test.runner.BuildConfiguration +import co.touchlab.skie.test.template.Templates +import co.touchlab.skie.test.util.KotlinTarget +import co.touchlab.skie.test.util.KotlinVersion +import co.touchlab.skie.test.util.LinkMode + +@Suppress("ClassName") +@Smoke +@GradleTests +class KotlinArtifactDsl_XCFramework_SingleTargetTests: BaseGradleTests() { + + @MatrixTest + fun `single target`( + kotlinVersion: KotlinVersion, + target: KotlinTarget.Native.Darwin, + linkMode: LinkMode, + configuration: BuildConfiguration, + ) { + rootBuildFile(kotlinVersion) { + kotlin { + target(target) + } + + kotlinArtifacts { + xcframework( + kotlinVersion = kotlinVersion, + targets = listOf(target), + linkMode = linkMode, + buildConfiguration = configuration, + ) + } + } + + copyToCommonMain(Templates.basic) + + runGradle() + + val frameworkParentName = when (target) { + KotlinTarget.Native.Ios.SimulatorArm64 -> "ios-arm64-simulator" + KotlinTarget.Native.Ios.X64 -> "ios-x86_64-simulator" + KotlinTarget.Native.Ios.Arm64 -> "ios-arm64" + KotlinTarget.Native.Tvos.SimulatorArm64 -> "tvos-arm64-simulator" + KotlinTarget.Native.Tvos.X64 -> "tvos-x86_64-simulator" + KotlinTarget.Native.Tvos.Arm64 -> "tvos-arm64" + KotlinTarget.Native.MacOS.Arm64 -> "macos-arm64" + KotlinTarget.Native.MacOS.X64 -> "macos-x86_64" + } + + buildSwift( + target, + Templates.basic, + frameworkParentPath = "build/out/xcframework/${configuration.name.lowercase()}/gradle_test.xcframework/$frameworkParentName", + ) + + if (target is KotlinTarget.Native.MacOS) { + runSwift() + } + } +} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_AllDarwinPresetsTests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_AllDarwinPresetsTests.kt new file mode 100644 index 00000000..97c31978 --- /dev/null +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_AllDarwinPresetsTests.kt @@ -0,0 +1,39 @@ +package co.touchlab.skie.test.suite.gradle.basic + +import co.touchlab.skie.test.annotation.MatrixTest +import co.touchlab.skie.test.annotation.filter.Smoke +import co.touchlab.skie.test.annotation.type.GradleTests +import co.touchlab.skie.test.base.BaseGradleTests +import co.touchlab.skie.test.runner.BuildConfiguration +import co.touchlab.skie.test.template.Templates +import co.touchlab.skie.test.util.KotlinTarget +import co.touchlab.skie.test.util.KotlinVersion +import co.touchlab.skie.test.util.LinkMode + +@Suppress("ClassName") +@GradleTests +class KotlinBinaryDsl_Framework_AllDarwinPresetsTests: BaseGradleTests() { + @Smoke + @MatrixTest + fun `basic project, all darwin presets`( + kotlinVersion: KotlinVersion, + buildConfiguration: BuildConfiguration, + linkMode: LinkMode, + ) { + rootBuildFile(kotlinVersion) { + kotlin { + targets(KotlinTarget.Native.Darwin) + + registerNativeFrameworks(kotlinVersion, buildConfiguration, linkMode) + } + } + + copyToCommonMain(Templates.basic) + + runGradle() + + KotlinTarget.Native.Darwin.targets.forEach { target -> + buildSwift(target, Templates.basic, builtFrameworkParentDir(target, buildConfiguration, isArtifactDsl = false)) + } + } +} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_SinglePreset.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_SinglePresetTests.kt similarity index 85% rename from test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_SinglePreset.kt rename to test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_SinglePresetTests.kt index ad1b10ab..9f0de854 100644 --- a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_SinglePreset.kt +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_SinglePresetTests.kt @@ -12,7 +12,7 @@ import co.touchlab.skie.test.util.LinkMode @Suppress("ClassName") @GradleTests -class BasicGradle_SinglePreset: BaseGradleTests() { +class KotlinBinaryDsl_Framework_SinglePresetTests: BaseGradleTests() { @Smoke @MatrixTest @@ -35,7 +35,7 @@ class BasicGradle_SinglePreset: BaseGradleTests() { runGradle() preset.targets.forEach { target -> - buildSwift(target, Templates.basic, buildConfiguration) + buildSwift(target, Templates.basic, builtFrameworkParentDir(target, buildConfiguration, isArtifactDsl = false)) } } } diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_SingleTarget.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_SingleTargetTests.kt similarity index 85% rename from test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_SingleTarget.kt rename to test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_SingleTargetTests.kt index 6bfce6c8..ab4597a4 100644 --- a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/BasicGradle_SingleTarget.kt +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/KotlinBinaryDsl_Framework_SingleTargetTests.kt @@ -12,7 +12,7 @@ import co.touchlab.skie.test.util.LinkMode @Suppress("ClassName") @GradleTests -class BasicGradle_SingleTarget: BaseGradleTests() { +class KotlinBinaryDsl_Framework_SingleTargetTests: BaseGradleTests() { @Smoke @MatrixTest fun `basic project, single target`( @@ -35,6 +35,6 @@ class BasicGradle_SingleTarget: BaseGradleTests() { runGradle() - buildSwift(target, Templates.basic, buildConfiguration) + buildSwift(target, Templates.basic, builtFrameworkParentDir(target, buildConfiguration, isArtifactDsl = false)) } } diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_NoArtifact_Tests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/NoArtifact_AllDarwinTargetsTests.kt similarity index 77% rename from test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_NoArtifact_Tests.kt rename to test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/NoArtifact_AllDarwinTargetsTests.kt index 96db3d62..a8c820a7 100644 --- a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/artifact/KotlinArtifactDsl_NoArtifact_Tests.kt +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/NoArtifact_AllDarwinTargetsTests.kt @@ -1,4 +1,4 @@ -package co.touchlab.skie.test.suite.gradle.artifact +package co.touchlab.skie.test.suite.gradle.basic import co.touchlab.skie.test.annotation.MatrixTest import co.touchlab.skie.test.annotation.filter.Smoke @@ -9,13 +9,13 @@ import co.touchlab.skie.test.util.KotlinVersion @Suppress("ClassName") @Smoke @GradleTests -class KotlinArtifactDsl_NoArtifact_Tests: BaseGradleTests() { +class NoArtifact_AllDarwinTargetsTests: BaseGradleTests() { @MatrixTest fun `no artifact`(kotlinVersion: KotlinVersion) { rootBuildFile(kotlinVersion) { kotlin { - allIos() + allDarwin() } } diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/NoArtifact_SingleTargetTests.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/NoArtifact_SingleTargetTests.kt new file mode 100644 index 00000000..29bfc38c --- /dev/null +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/suite/gradle/basic/NoArtifact_SingleTargetTests.kt @@ -0,0 +1,28 @@ +package co.touchlab.skie.test.suite.gradle.basic + +import co.touchlab.skie.test.annotation.MatrixTest +import co.touchlab.skie.test.annotation.filter.Smoke +import co.touchlab.skie.test.annotation.type.GradleTests +import co.touchlab.skie.test.base.BaseGradleTests +import co.touchlab.skie.test.util.KotlinTarget +import co.touchlab.skie.test.util.KotlinVersion + +@Suppress("ClassName") +@Smoke +@GradleTests +class NoArtifact_SingleTargetTests: BaseGradleTests() { + + @MatrixTest + fun `no artifact`( + kotlinVersion: KotlinVersion, + kotlinTarget: KotlinTarget, + ) { + rootBuildFile(kotlinVersion) { + kotlin { + target(kotlinTarget) + } + } + + runGradle() + } +} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/trait/gradle/BuildGradleBuilder.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/trait/gradle/BuildGradleBuilder.kt index bc57729b..4ff04147 100644 --- a/test-runner/src/test/kotlin/co/touchlab/skie/test/trait/gradle/BuildGradleBuilder.kt +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/trait/gradle/BuildGradleBuilder.kt @@ -4,6 +4,7 @@ import co.touchlab.skie.test.runner.BuildConfiguration import co.touchlab.skie.test.util.KotlinTarget import co.touchlab.skie.test.util.KotlinVersion import co.touchlab.skie.test.util.LinkMode +import org.intellij.lang.annotations.Language class BuildGradleBuilder( val kotlinVersion: KotlinVersion, @@ -12,29 +13,30 @@ class BuildGradleBuilder( Plugin.skie, ), ) { - private val imports = mutableListOf() + private val imports = mutableSetOf() private val builder = StringBuilder() + private var builderIndentationLevel = 0 init { if (plugins.isNotEmpty()) { - +"plugins {" - plugins.forEach { - +" ${it.application}" + "plugins" { + plugins.forEach { + +it.application + } } - +"}" } } fun kotlin(block: KotlinExtensionScope.() -> Unit) { - +"kotlin {" - KotlinExtensionScope().block() - +"}" + "kotlin" { + KotlinExtensionScope().block() + } } fun kotlinArtifacts(block: KotlinArtifactsExtensionScope.() -> Unit) { - +"kotlinArtifacts {" - KotlinArtifactsExtensionScope().block() - +"}" + "kotlinArtifacts" { + KotlinArtifactsExtensionScope().block() + } } fun workaroundFatFrameworkConfigurationIfNeeded( @@ -43,29 +45,54 @@ class BuildGradleBuilder( if (kotlinVersion.value.startsWith("1.8.")) { imports.add("org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask") - +"tasks.withType().configureEach {" - +" configurations.getByName(" - +" name.substringAfter(\"link\").replaceFirstChar { it.lowercase() }" - +" ).attributes {" - +" attribute(Attribute.of(\"fat-framework\", String::class.java), \"true\")" - +" }" - +"}" + appendLines(""" + tasks.withType().configureEach { + configurations.getByName( + name.substringAfter("link").replaceFirstChar { it.lowercase() } + ).attributes { + attribute(Attribute.of("fat-framework", String::class.java), "true") + } + } + """.trimIndent()) + } + } + + fun appendLines(@Language("kotlin") code: String) { + code.lines().forEach { + +it } } - operator fun String.unaryPlus() { + operator fun @receiver:Language("kotlin") String.unaryPlus() { + appendIndentation() builder.appendLine(this) } + operator fun @receiver:Language("kotlin") String.invoke(block: () -> Unit) { + appendIndentation() + builder.append(this) + builder.appendLine(" {") + builderIndentationLevel += 1 + block() + builderIndentationLevel -= 1 + builder.appendLine("}") + } + + private fun appendIndentation() { + repeat(builderIndentationLevel) { + builder.append(" ") + } + } + override fun toString(): String { - return co.touchlab.skie.test.util.buildString { - imports.forEach { - +"import $it\n" + return buildString { + imports.sorted().forEach { + this.appendLine("import $it") } if (imports.isNotEmpty()) { - +"\n" + this.appendLine() } - +builder + this.append(builder) } } @@ -86,11 +113,12 @@ class BuildGradleBuilder( fun allMacos() = targets(KotlinTarget.Native.MacOS) -// fun allTvos() = targets(Native.Tvos) + fun allTvos() = targets(KotlinTarget.Native.Tvos) fun allDarwin() { allIos() allMacos() + allTvos() // TODO: allTvos() // TODO: allWatchos() } @@ -115,44 +143,63 @@ class BuildGradleBuilder( ) { imports.add("org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget") imports.add("org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType") - +"targets.withType {" - +" binaries {" - +" framework(buildTypes = listOf(NativeBuildType.${buildConfiguration.name.uppercase()})) {" - +" isStatic = ${linkMode.isStatic}" - +" freeCompilerArgs = freeCompilerArgs + listOf(\"-Xbinary=bundleId=gradle_test\")" - if (kotlinVersion.value.startsWith("1.8.") || kotlinVersion.value.startsWith("1.9.0")) { - +" linkerOpts += \"-ld64\"" - } - +" }" - +" }" - +"}" - } - operator fun String.unaryPlus() { - builder.appendLine(" $this") + "targets.withType" { + "binaries" { + "framework(buildTypes = listOf(NativeBuildType.${buildConfiguration.name.uppercase()}))" { + +"isStatic = ${linkMode.isStatic}" + +"""freeCompilerArgs = freeCompilerArgs + listOf("-Xbinary=bundleId=gradle_test")""" + if (kotlinVersion.value.startsWith("1.8.") || kotlinVersion.value.startsWith("1.9.0")) { + +"""linkerOpts += "-ld64"""" + } + } + } + } } } inner class KotlinArtifactsExtensionScope { fun framework( + kotlinVersion: KotlinVersion, target: KotlinTarget.Native, linkMode: LinkMode, buildConfiguration: BuildConfiguration, ) { imports.add("org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType") - +"""Native.Framework {""" - +" target = ${target.id}" - +" isStatic = ${linkMode.isStatic}" - +" modes(NativeBuildTye.${buildConfiguration.name.uppercase()})" - +" toolOptions {" - +" freeCompilerArgs.add(\"-Xbinary=bundleId=gradle_test\")" - +" }" - +"}" + + "Native.Framework" { + +"target = ${target.id}" + +"isStatic = ${linkMode.isStatic}" + +"modes(NativeBuildType.${buildConfiguration.name.uppercase()})" + "toolOptions" { + +"""freeCompilerArgs.add("-Xbinary=bundleId=gradle_test")""" + } + if (kotlinVersion.value.startsWith("1.8.") || kotlinVersion.value.startsWith("1.9.0")) { + +"""linkerOptions += "-ld64"""" + } + } } - operator fun String.unaryPlus() { - builder.appendLine(" $this") + fun xcframework( + kotlinVersion: KotlinVersion, + targets: List, + linkMode: LinkMode, + buildConfiguration: BuildConfiguration, + ) { + imports.add("org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType") + + "Native.XCFramework" { + +"targets(${targets.joinToString { it.id }})" + +"modes(${buildConfiguration.toString().uppercase()})" + +"isStatic = ${linkMode.isStatic}" + "toolOptions" { + +"""freeCompilerArgs.add("-Xbinary=bundleId=gradle_test")""" + } + if (kotlinVersion.value.startsWith("1.8.") || kotlinVersion.value.startsWith("1.9.0")) { + +"""linkerOptions += "-ld64"""" + } + } } } diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/util/BuildResult.shouldBeSuccess.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/util/BuildResult.shouldBeSuccess.kt new file mode 100644 index 00000000..a4233c48 --- /dev/null +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/util/BuildResult.shouldBeSuccess.kt @@ -0,0 +1,9 @@ +package co.touchlab.skie.test.util + +import io.kotest.matchers.collections.shouldBeEmpty +import org.gradle.testkit.runner.BuildResult +import org.gradle.testkit.runner.TaskOutcome + +fun BuildResult.shouldBeSuccess() { + this.tasks(TaskOutcome.FAILED).shouldBeEmpty() +} diff --git a/test-runner/src/test/kotlin/co/touchlab/skie/test/util/BuildTask.shouldBeSuccess.kt b/test-runner/src/test/kotlin/co/touchlab/skie/test/util/BuildTask.shouldBeSuccess.kt new file mode 100644 index 00000000..0eabf526 --- /dev/null +++ b/test-runner/src/test/kotlin/co/touchlab/skie/test/util/BuildTask.shouldBeSuccess.kt @@ -0,0 +1,11 @@ +package co.touchlab.skie.test.util + +import io.kotest.matchers.nulls.shouldNotBeNull +import io.kotest.matchers.shouldBe +import org.gradle.testkit.runner.BuildTask +import org.gradle.testkit.runner.TaskOutcome + +fun BuildTask?.shouldBeSuccess() { + this.shouldNotBeNull() + .outcome shouldBe TaskOutcome.SUCCESS +} diff --git a/test-runner/src/test/resources/junit-platform.properties b/test-runner/src/test/resources/junit-platform.properties index b12779b4..f61dfae8 100644 --- a/test-runner/src/test/resources/junit-platform.properties +++ b/test-runner/src/test/resources/junit-platform.properties @@ -1,7 +1,7 @@ -junit.jupiter.execution.parallel.enabled = true -junit.jupiter.execution.parallel.mode.default = concurrent -junit.jupiter.execution.parallel.mode.classes.default = concurrent -junit.jupiter.execution.parallel.config.strategy = dynamic - -junit.platform.output.capture.stdout=true -junit.platform.output.capture.stderr=true +#junit.jupiter.execution.parallel.enabled = true +#junit.jupiter.execution.parallel.mode.default = concurrent +#junit.jupiter.execution.parallel.mode.classes.default = concurrent +#junit.jupiter.execution.parallel.config.strategy = dynamic +# +#junit.platform.output.capture.stdout=true +#junit.platform.output.capture.stderr=true