[Gradle] Check ~/.konan after each test class
Added deleting ~/.konan before kotlin-gradle-plugin-integration-tests execution. And added checking ~/.konan after each test class. This is necessary to check that in each test konan.data.dir gradle property is set properly
This commit is contained in:
committed by
Space Team
parent
b15787bfa8
commit
8e71488adf
@@ -12,6 +12,7 @@ More fine-grained test tasks exist covering different parts of Gradle plugins:
|
||||
- `kgpJsTests` - runs all tests for Kotlin Gradle Plugin/Js platform (parallel execution)
|
||||
- `kgpAndroidTests` - runs all tests for Kotlin Gradle Plugin/Android platform (parallel execution)
|
||||
- `kgpMppTests` - run all tests for Kotlin Gradle Multiplatform plugin (parallel execution)
|
||||
- `kgpNativeTests` - run all tests for Kotlin Gradle Plugin with K/N (parallel execution)
|
||||
- `kgpDaemonTests` - runs all tests for Gradle and Kotlin daemons (sequential execution)
|
||||
- `kgpOtherTests` - run all tests for support Gradle plugins, such as kapt, allopen, etc (parallel execution)
|
||||
- `kgpAllParallelTests` - run all tests for all platforms except daemons tests (parallel execution)
|
||||
@@ -30,7 +31,7 @@ also require the Gradle plugin marker artifacts to be installed:
|
||||
|
||||
If you want to run only one test class, you need to append `--tests` flag with value of test class, which you want to run
|
||||
```shell
|
||||
./gradlew :kotlin-gradle-plugin-integration-tests:kgpAllTests --tests <class-name-with-package>
|
||||
./gradlew :kotlin-gradle-plugin-integration-tests:kgpAllParallelTests --tests <class-name-with-package>
|
||||
```
|
||||
|
||||
#### How to work with the tests
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.gradle.jvm.toolchain.internal.NoToolchainAvailableException
|
||||
import org.jetbrains.kotlin.pill.PillExtension
|
||||
import java.nio.file.Paths
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
@@ -128,6 +129,16 @@ val cleanTestKitCacheTask = tasks.register<Delete>("cleanTestKitCache") {
|
||||
delete(project.buildDir.resolve("testKitCache"))
|
||||
}
|
||||
|
||||
tasks.register<Delete>("cleanUserHomeKonanDir") {
|
||||
group = KGP_TEST_TASKS_GROUP
|
||||
description = "Deletes ~/.konan dir before tests. This step is necessary to ensure that no test inadvertently creates this directory during execution."
|
||||
|
||||
val userHomeKonanDir = Paths.get("${System.getProperty("user.home")}/.konan")
|
||||
delete(userHomeKonanDir)
|
||||
|
||||
println("Default .konan directory user's home has been deleted: $userHomeKonanDir")
|
||||
}
|
||||
|
||||
fun Test.includeMppAndAndroid(include: Boolean) = includeTestsWithPattern(include) {
|
||||
addAll(listOf("*Multiplatform*", "*Mpp*", "*Android*"))
|
||||
}
|
||||
@@ -329,6 +340,9 @@ tasks.withType<Test> {
|
||||
dependsOn(":gradle:kotlin-compiler-args-properties:install")
|
||||
dependsOn(":examples:annotation-processor-example:install")
|
||||
dependsOn(":kotlin-dom-api-compat:install")
|
||||
if (project.kotlinBuildProperties.isTeamcityBuild) {
|
||||
dependsOn(":kotlin-gradle-plugin-integration-tests:cleanUserHomeKonanDir")
|
||||
}
|
||||
|
||||
systemProperty("kotlinVersion", rootProject.extra["kotlinVersion"] as String)
|
||||
systemProperty("runnerGradleVersion", gradle.gradleVersion)
|
||||
|
||||
+1
@@ -331,6 +331,7 @@ class BuildCacheRelocationIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmGradlePluginTests
|
||||
@DisplayName("Kotlin incremental compilation with `kotlin.incremental.classpath.snapshot.enabled` feature should work correctly")
|
||||
@GradleTest
|
||||
fun testKotlinIncrementalCompilation_withICClasspathSnapshot(gradleVersion: GradleVersion) {
|
||||
|
||||
+3
-1
@@ -19,7 +19,6 @@ import kotlin.io.path.exists
|
||||
import kotlin.io.path.name
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.fail
|
||||
|
||||
@OsCondition(supportedOn = [OS.MAC], enabledOnCI = [OS.MAC])
|
||||
@DisplayName("K/N tests cocoapods with xcodebuild")
|
||||
@@ -201,6 +200,9 @@ class CocoaPodsXcodeIT : KGPBaseTest() {
|
||||
?.let {
|
||||
it.append("kotlin_version=${defaultBuildOptions.kotlinVersion}")
|
||||
it.append("test_fixes_version=${defaultBuildOptions.kotlinVersion}")
|
||||
defaultBuildOptions.konanDataDir?.let { konanDataDir ->
|
||||
it.append("konan.data.dir=${konanDataDir.toAbsolutePath().normalize()}")
|
||||
}
|
||||
}
|
||||
|
||||
for ((subproject, frameworkName) in subprojectsToFrameworkNamesMap) {
|
||||
|
||||
+1
-31
@@ -14,8 +14,8 @@ import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.presetName
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assumptions
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
@@ -51,36 +51,6 @@ class NativeDownloadAndPlatformLibsIT : KGPBaseTest() {
|
||||
.apply { mkdirs() }.toPath()
|
||||
)
|
||||
|
||||
@AfterEach
|
||||
fun checkThatUserKonanDirIsEmptyAfterTest() {
|
||||
val userHomeDir = System.getProperty("user.home")
|
||||
assertFileNotExists(Paths.get("$userHomeDir/.konan/kotlin-native-prebuilt-$platformName-$currentCompilerVersion"))
|
||||
}
|
||||
|
||||
@DisplayName("Downloading K/N distribution in default .konan dir")
|
||||
@GradleTest
|
||||
fun testLibrariesGenerationInDefaultKonanDir(gradleVersion: GradleVersion) {
|
||||
|
||||
checkThatUserKonanDirIsEmptyAfterTest()
|
||||
|
||||
val userHomeDir = System.getProperty("user.home")
|
||||
platformLibrariesProject("linuxX64", gradleVersion = gradleVersion) {
|
||||
build("assemble", buildOptions = defaultBuildOptions.copy(konanDataDir = null)) {
|
||||
assertOutputContains("Kotlin/Native distribution: .*kotlin-native-prebuilt-$platformName".toRegex())
|
||||
assertOutputDoesNotContain("Generate platform libraries for ")
|
||||
|
||||
// checking that konan was downloaded and native dependencies were not downloaded into ~/.konan dir
|
||||
assertDirectoryExists(Paths.get("$userHomeDir/.konan/dependencies"))
|
||||
assertDirectoryExists(Paths.get("$userHomeDir/.konan/kotlin-native-prebuilt-$platformName-$currentCompilerVersion"))
|
||||
}
|
||||
}
|
||||
|
||||
// clean ~/.konan after test it should not be with all inheritors of KGPBaseTest
|
||||
Paths.get("$userHomeDir/.konan/dependencies").deleteRecursively()
|
||||
Paths.get("$userHomeDir/.konan/kotlin-native-prebuilt-$platformName-$currentCompilerVersion").deleteRecursively()
|
||||
|
||||
}
|
||||
|
||||
@OptIn(EnvironmentalVariablesOverride::class)
|
||||
@DisplayName("K/N Gradle project build (on Linux or Mac) with a dependency from a Maven")
|
||||
@GradleTest
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.native
|
||||
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.appendText
|
||||
import kotlin.io.path.deleteRecursively
|
||||
|
||||
class NativeDownloadAndPlatformLibsNonParallelIT : KGPDaemonsBaseTest() {
|
||||
|
||||
private val platformName: String = HostManager.platformName()
|
||||
private val currentCompilerVersion = NativeCompilerDownloader.DEFAULT_KONAN_VERSION
|
||||
|
||||
|
||||
@DisplayName("Downloading K/N distribution in default .konan dir")
|
||||
@GradleTest
|
||||
fun testLibrariesGenerationInDefaultKonanDir(gradleVersion: GradleVersion) {
|
||||
|
||||
checkThatDefaultKonanHasNotBeenCreated()
|
||||
|
||||
val userHomeDir = System.getProperty("user.home")
|
||||
platformLibrariesProject("linuxX64", gradleVersion = gradleVersion) {
|
||||
build("assemble", buildOptions = defaultBuildOptions.copy(konanDataDir = null)) {
|
||||
assertOutputContains("Kotlin/Native distribution: .*kotlin-native-prebuilt-$platformName".toRegex())
|
||||
assertOutputDoesNotContain("Generate platform libraries for ")
|
||||
|
||||
// checking that konan was downloaded and native dependencies were not downloaded into ~/.konan dir
|
||||
assertDirectoryExists(Paths.get("$userHomeDir/.konan/dependencies"))
|
||||
assertDirectoryExists(Paths.get("$userHomeDir/.konan/kotlin-native-prebuilt-$platformName-$currentCompilerVersion"))
|
||||
}
|
||||
}
|
||||
|
||||
// clean ~/.konan after test it should not be with all inheritors of KGPBaseTest
|
||||
Paths.get("$userHomeDir/.konan").deleteRecursively()
|
||||
|
||||
}
|
||||
|
||||
private fun platformLibrariesProject(
|
||||
vararg targets: String,
|
||||
gradleVersion: GradleVersion,
|
||||
test: TestProject.() -> Unit = {},
|
||||
) {
|
||||
nativeProject("native-platform-libraries", gradleVersion) {
|
||||
buildGradleKts.appendText(
|
||||
targets.joinToString(prefix = "\n", separator = "\n") {
|
||||
"kotlin.$it()"
|
||||
}
|
||||
)
|
||||
test()
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -7,10 +7,12 @@ package org.jetbrains.kotlin.gradle.testbase
|
||||
|
||||
import com.intellij.testFramework.TestDataPath
|
||||
import org.jetbrains.kotlin.test.WithMuteInDatabase
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
/**
|
||||
* Base class for all Kotlin Gradle plugin integration tests.
|
||||
@@ -37,4 +39,12 @@ abstract class KGPBaseTest {
|
||||
lateinit var workingDir: Path
|
||||
|
||||
internal open fun TestProject.customizeProject() {}
|
||||
|
||||
@AfterAll
|
||||
fun checkThatDefaultKonanHasNotBeenCreated() {
|
||||
if (System.getenv("TEAMCITY_VERSION") != null) {
|
||||
val userHomeDir = System.getProperty("user.home")
|
||||
assertDirectoryDoesNotExist(Paths.get("$userHomeDir/.konan"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user