[Gradle] Add integration tests for KT-34901

This commit is contained in:
Alexander.Likhachev
2023-06-29 14:11:47 +02:00
committed by Space Team
parent 792b6482c0
commit fcb7010726
9 changed files with 212 additions and 0 deletions
@@ -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"
}
}
@@ -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()
}
@@ -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"
}
@@ -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())
}
}
@@ -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")
@@ -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()
}
@@ -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"
}
@@ -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())
}
}
@@ -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")