From fcb70107267b733e6a06cd7a87c2c3aa6f29709d Mon Sep 17 00:00:00 2001 From: "Alexander.Likhachev" Date: Thu, 29 Jun 2023 14:11:47 +0200 Subject: [PATCH] [Gradle] Add integration tests for KT-34901 --- .../jetbrains/kotlin/gradle/TestFixturesIT.kt | 106 ++++++++++++++++++ .../jvm-test-fixtures/build.gradle | 17 +++ .../jvm-test-fixtures/src/main/kotlin/City.kt | 10 ++ .../src/test/kotlin/Tests.kt | 16 +++ .../src/testFixtures/kotlin/Netherlands.kt | 5 + .../mpp-test-fixtures/build.gradle | 27 +++++ .../src/jvmMain/kotlin/City.kt | 10 ++ .../src/jvmTest/kotlin/Tests.kt | 16 +++ .../src/jvmTestFixtures/kotlin/Netherlands.kt | 5 + 9 files changed, 212 insertions(+) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/TestFixturesIT.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/build.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/main/kotlin/City.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/test/kotlin/Tests.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/testFixtures/kotlin/Netherlands.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/build.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmMain/kotlin/City.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmTest/kotlin/Tests.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmTestFixtures/kotlin/Netherlands.kt diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/TestFixturesIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/TestFixturesIT.kt new file mode 100644 index 00000000000..43cd64ba366 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/TestFixturesIT.kt @@ -0,0 +1,106 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle + +import org.gradle.util.GradleVersion +import org.jetbrains.kotlin.gradle.testbase.* +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.DisplayName +import kotlin.io.path.appendText + +@DisplayName("Integration with the Gradle java-test-fixtures plugin") +class TestFixturesIT : KGPBaseTest() { + @Disabled + @DisplayName("Test fixtures can access internals of the main source set in Kotlin/JVM projects") + @JvmGradlePluginTests + @GradleTest + fun testInternalAccessInJvmProject(gradleVersion: GradleVersion) { + project(JVM_TEST_FIXTURES_PROJECT_NAME, gradleVersion) { + kotlinSourcesDir("testFixtures").resolve("Netherlands.kt").appendText( + //language=kt + """ + + fun isCityFromNetherlands(city: City) = city.isNetherlands() + """.trimIndent() + ) + + build("compileTestFixturesKotlin") + } + } + + @Disabled + @DisplayName("Test fixtures can access internals of the main JVM source set in Kotlin MPP projects") + @MppGradlePluginTests + @GradleTest + fun testInternalAccessInMppProject(gradleVersion: GradleVersion) { + project(MPP_TEST_FIXTURES_PROJECT_NAME, gradleVersion) { + kotlinSourcesDir("jvmTestFixtures").resolve("Netherlands.kt").appendText( + //language=kt + """ + + fun isCityFromNetherlands(city: City) = city.isNetherlands() + """.trimIndent() + ) + + build("compileTestFixturesKotlinJvm") + } + } + + @Disabled + @DisplayName("Test code can access internals of the test fixtures source set in Kotlin/JVM projects") + @JvmGradlePluginTests + @GradleTest + fun testInternalAccessFromTestsInJvmProject(gradleVersion: GradleVersion) { + project(JVM_TEST_FIXTURES_PROJECT_NAME, gradleVersion) { + kotlinSourcesDir("testFixtures").resolve("Netherlands.kt").appendText( + //language=kt + """ + + internal fun isCityFromNetherlands(city: City) = city.isNetherlands() + """.trimIndent() + ) + + kotlinSourcesDir("test").resolve("Tests.kt").modify { + it.replace( + "assertEquals(true, AMSTERDAM.isNetherlands())", + "assertEquals(AMSTERDAM.isNetherlands(), isCityFromNetherlands(AMSTERDAM))" + ) + } + + build("compileTestKotlin") + } + } + + @Disabled + @DisplayName("JVM test code can access internals of the test fixtures source set in Kotlin MPP projects") + @MppGradlePluginTests + @GradleTest + fun testInternalAccessFromTestsInMppProject(gradleVersion: GradleVersion) { + project(MPP_TEST_FIXTURES_PROJECT_NAME, gradleVersion) { + kotlinSourcesDir("jvmTestFixtures").resolve("Netherlands.kt").appendText( + //language=kt + """ + + internal fun isCityFromNetherlands(city: City) = city.isNetherlands() + """.trimIndent() + ) + + kotlinSourcesDir("jvmTest").resolve("Tests.kt").modify { + it.replace( + "assertEquals(true, AMSTERDAM.isNetherlands())", + "assertEquals(AMSTERDAM.isNetherlands(), isCityFromNetherlands(AMSTERDAM))" + ) + } + + build("compileTestKotlinJvm") + } + } + + companion object { + private const val JVM_TEST_FIXTURES_PROJECT_NAME = "jvm-test-fixtures" + private const val MPP_TEST_FIXTURES_PROJECT_NAME = "mpp-test-fixtures" + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/build.gradle new file mode 100644 index 00000000000..1ca25134494 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/build.gradle @@ -0,0 +1,17 @@ +plugins { + id("org.jetbrains.kotlin.jvm") + id("java-test-fixtures") +} + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") +} + +tasks.named("test").configure { + useJUnitPlatform() +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/main/kotlin/City.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/main/kotlin/City.kt new file mode 100644 index 00000000000..25bd6c6576d --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/main/kotlin/City.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.example + +class City(val name: String, val country: String) { + internal fun isNetherlands(): Boolean = country == "The Netherlands" +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/test/kotlin/Tests.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/test/kotlin/Tests.kt new file mode 100644 index 00000000000..bf004ff9606 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/test/kotlin/Tests.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.example + +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class Tests { + @Test + fun testCity() { + assertEquals(true, AMSTERDAM.isNetherlands()) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/testFixtures/kotlin/Netherlands.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/testFixtures/kotlin/Netherlands.kt new file mode 100644 index 00000000000..a4a29cf2fe4 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/jvm-test-fixtures/src/testFixtures/kotlin/Netherlands.kt @@ -0,0 +1,5 @@ +package org.example + +val AMSTERDAM = City("Amsterdam", "The Netherlands") +val UTRECHT = City("Utrecht", "The Netherlands") +val THE_HAGUE = City("The Hague", "The Netherlands") \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/build.gradle new file mode 100644 index 00000000000..1f7dae00a91 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/build.gradle @@ -0,0 +1,27 @@ +plugins { + id("org.jetbrains.kotlin.multiplatform") + id("java-test-fixtures") +} + +repositories { + mavenLocal() + mavenCentral() +} + +kotlin { + jvm() { + withJava() + } + + sourceSets { + named("jvmTest") { + dependencies { + implementation("org.jetbrains.kotlin:kotlin-test-junit5") + } + } + } +} + +tasks.named("test").configure { + useJUnitPlatform() +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmMain/kotlin/City.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmMain/kotlin/City.kt new file mode 100644 index 00000000000..25bd6c6576d --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmMain/kotlin/City.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.example + +class City(val name: String, val country: String) { + internal fun isNetherlands(): Boolean = country == "The Netherlands" +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmTest/kotlin/Tests.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmTest/kotlin/Tests.kt new file mode 100644 index 00000000000..bf004ff9606 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmTest/kotlin/Tests.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.example + +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class Tests { + @Test + fun testCity() { + assertEquals(true, AMSTERDAM.isNetherlands()) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmTestFixtures/kotlin/Netherlands.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmTestFixtures/kotlin/Netherlands.kt new file mode 100644 index 00000000000..a4a29cf2fe4 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/mpp-test-fixtures/src/jvmTestFixtures/kotlin/Netherlands.kt @@ -0,0 +1,5 @@ +package org.example + +val AMSTERDAM = City("Amsterdam", "The Netherlands") +val UTRECHT = City("Utrecht", "The Netherlands") +val THE_HAGUE = City("The Hague", "The Netherlands") \ No newline at end of file