From 654617523cd03aec3d0db09a448248b55ccc839a Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Thu, 19 Jul 2018 16:17:55 +0700 Subject: [PATCH] [gradle-plugin][tests] Add test for unsupported targets --- .../test/kotlin/ExperimentalPluginTests.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/kotlin-native-gradle-plugin/src/test/kotlin/ExperimentalPluginTests.kt b/tools/kotlin-native-gradle-plugin/src/test/kotlin/ExperimentalPluginTests.kt index 42c3caff14c..3f4b7187174 100644 --- a/tools/kotlin-native-gradle-plugin/src/test/kotlin/ExperimentalPluginTests.kt +++ b/tools/kotlin-native-gradle-plugin/src/test/kotlin/ExperimentalPluginTests.kt @@ -1,6 +1,12 @@ package org.jetbrains.kotlin.gradle.plugin.test +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.internal.project.ProjectInternal +import org.gradle.testfixtures.ProjectBuilder import org.gradle.testkit.runner.TaskOutcome +import org.jetbrains.kotlin.gradle.plugin.experimental.internal.KotlinNativeMainComponent +import org.jetbrains.kotlin.gradle.plugin.experimental.plugins.KotlinNativePlugin import org.jetbrains.kotlin.konan.target.HostManager import org.jetbrains.kotlin.konan.target.KonanTarget import org.junit.Rule @@ -20,6 +26,21 @@ class ExperimentalPluginTests { val exeSuffix = HostManager.host.family.exeSuffix + private fun withProject( + name: String = "testProject", + plugins: Collection>> = listOf(KotlinNativePlugin::class.java), + parent: Project? = null, + block: ProjectInternal.() -> Unit + ) { + val builder = ProjectBuilder.builder().withProjectDir(projectDirectory).withName(name) + parent?.let { builder.withParent(it) } + val project = builder.build() as ProjectInternal + plugins.forEach { + project.pluginManager.apply(it) + } + project.block() + } + @Test fun `Plugin should compile one executable`() { val project = KonanProject.create(projectDirectory).apply { @@ -374,4 +395,20 @@ class ExperimentalPluginTests { assertTrue(projectDirectory.resolve("build/exe/foo/release/foo.$exeSuffix").exists()) } + @Test + fun `Plugin should not create compilation tasks for targets unsupported by the current host`() = + withProject { + val hosts = arrayOf("macos_x64", "linux_x64", "mingw_x64") + components.withType(KotlinNativeMainComponent::class.java).getByName("main").target(*hosts) + evaluate() + hosts.map { HostManager().targetByName(it) }.forEach { + val task = tasks.findByName("compileDebug${it.name.capitalize()}KotlinNative") + + if (it == HostManager.host) { + assertNotNull(task) + } else { + assertNull(task) + } + } + } } \ No newline at end of file