[Gradle] Add tests for KT-52149, KT-55174, and KT-55741

This commit is contained in:
Alexander.Likhachev
2023-01-12 13:59:20 +01:00
committed by Space Team
parent c8db20bd0b
commit d360feb847
2 changed files with 104 additions and 1 deletions
@@ -0,0 +1,90 @@
/*
* 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.api.logging.configuration.WarningMode
import org.gradle.testkit.runner.BuildResult
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.DisplayName
@DisplayName("Build services usages in tasks are declared with `usesService`")
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_5)
class BuildServiceDeclarationIT : KGPBaseTest() {
override val defaultBuildOptions = super.defaultBuildOptions.copy(
warningMode = WarningMode.All // we currently have other warnings when `STABLE_CONFIGURATION_CACHE` is enabled unrelated to build services declaration, so we check for this kind of warnings in the build output
)
@Disabled
@DisplayName("Build services are registered for Kotlin/JVM projects")
@GradleTest
@JvmGradlePluginTests
fun testJvmProject(gradleVersion: GradleVersion) {
project("kotlinJavaProject", gradleVersion) {
enableStableConfigurationCachePreview()
build("build") {
assertOutputDoesNotContainBuildServiceDeclarationWarnings()
}
}
}
@Disabled
@DisplayName("Build services are registered for Kotlin/JS nodejs projects")
@GradleTest
@JsGradlePluginTests
fun testJsNodeJsProject(gradleVersion: GradleVersion) {
project("kotlin-js-browser-project", gradleVersion) {
enableStableConfigurationCachePreview()
build("build") {
assertOutputDoesNotContainBuildServiceDeclarationWarnings()
}
}
}
@Disabled
@DisplayName("Build services are registered for Kotlin/JS browser projects")
@GradleTest
@JsGradlePluginTests
fun testJsBrowserProject(gradleVersion: GradleVersion) {
project("kotlin-js-nodejs-project", gradleVersion) {
enableStableConfigurationCachePreview()
build("build") {
assertOutputDoesNotContainBuildServiceDeclarationWarnings()
}
}
}
@Disabled
@DisplayName("Build services are registered for Kotlin/MPP projects")
@GradleTest
@MppGradlePluginTests
fun testMppProject(gradleVersion: GradleVersion) {
project("new-mpp-lib-with-tests", gradleVersion) {
enableStableConfigurationCachePreview()
build("build") {
assertOutputDoesNotContainBuildServiceDeclarationWarnings()
}
}
}
@Disabled
@DisplayName("Build services are registered for Kapt projects")
@GradleTest
@OtherGradlePluginTests
fun testKaptProject(gradleVersion: GradleVersion) {
project("kapt2/simple", gradleVersion) {
enableStableConfigurationCachePreview()
build("build") {
assertOutputDoesNotContainBuildServiceDeclarationWarnings()
}
}
}
private fun BuildResult.assertOutputDoesNotContainBuildServiceDeclarationWarnings() {
assertOutputDoesNotContain("without the corresponding declaration via 'Task#usesService'")
}
}
@@ -485,7 +485,6 @@ private fun TestProject.setupNonDefaultJdk(pathToJdk: File) {
}
}
@OptIn(ExperimentalPathApi::class)
internal fun Path.enableAndroidSdk() {
val androidSdk = KtTestUtil.findAndroidSdk()
resolve("local.properties")
@@ -610,3 +609,17 @@ private fun TestProject.configureLocalRepository(localRepoDir: Path) {
}
internal fun TestProject.disableKotlinNativeCaches() = gradleProperties.toFile().disableKotlinNativeCaches()
internal fun TestProject.enableStableConfigurationCachePreview() {
val settingsFile = if (settingsGradleKts.exists()) {
settingsGradleKts
} else {
settingsGradle
}
settingsFile.append(
"""
|
|enableFeaturePreview("STABLE_CONFIGURATION_CACHE")
""".trimMargin()
)
}