[MPP] Emit a warning when kotlin-test testing framework couldn't be inferred
^KT-56828
This commit is contained in:
committed by
Space Team
parent
3b9b9327a4
commit
256d9da24c
+7
@@ -28,6 +28,9 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
||||||
import org.jetbrains.kotlin.gradle.execution.KotlinAggregateExecutionSource
|
import org.jetbrains.kotlin.gradle.execution.KotlinAggregateExecutionSource
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.diagnostics.reportDiagnostic
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
||||||
@@ -144,6 +147,10 @@ private fun Configuration.maybeAddTestDependencyCapability(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
compilation.project.reportDiagnostic(
|
||||||
|
KotlinToolingDiagnostics.KotlinTestFrameworkInferenceFailed(name)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -520,6 +520,16 @@ object KotlinToolingDiagnostics {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object KotlinTestFrameworkInferenceFailed : ToolingDiagnosticFactory(WARNING) {
|
||||||
|
operator fun invoke(configurationName: String) = build(
|
||||||
|
"""
|
||||||
|
kotlin-test was added to a non-testing configuration "$configurationName" where test framework couldn't be inferred.
|
||||||
|
|
||||||
|
Learn how to configure kotlin-test at: https://kotl.in/kotlin-test-frameworks
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
object XCFrameworkDifferentInnerFrameworksName : ToolingDiagnosticFactory(WARNING) {
|
object XCFrameworkDifferentInnerFrameworksName : ToolingDiagnosticFactory(WARNING) {
|
||||||
operator fun invoke(xcFramework: String, innerFrameworks: String) = build(
|
operator fun invoke(xcFramework: String, innerFrameworks: String) = build(
|
||||||
"Name of XCFramework '$xcFramework' differs from inner frameworks name '$innerFrameworks'! Framework renaming is not supported yet"
|
"Name of XCFramework '$xcFramework' differs from inner frameworks name '$innerFrameworks'! Framework renaming is not supported yet"
|
||||||
|
|||||||
+116
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("FunctionName")
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.dependencyResolutionTests
|
||||||
|
|
||||||
|
import org.gradle.api.NamedDomainObjectProvider
|
||||||
|
import org.gradle.api.artifacts.Configuration
|
||||||
|
import org.gradle.api.internal.project.ProjectInternal
|
||||||
|
import org.gradle.kotlin.dsl.dependencies
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformSourceSetConventionsImpl.dependencies
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.extraProperties
|
||||||
|
import org.jetbrains.kotlin.gradle.util.*
|
||||||
|
import org.jetbrains.kotlin.gradle.util.assertNoDiagnostics
|
||||||
|
import kotlin.test.Test
|
||||||
|
|
||||||
|
class KotlinTestFrameworkInferenceFailedTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `KMP project - when jvmTest depends on kotlin-test - emits no diagnostics`() {
|
||||||
|
evaluateProjectAndResolveConfigurationsWhen {
|
||||||
|
kmpProjectWithJvm { sourceSets.jvmTest.dependOnKotlinTest() }
|
||||||
|
}.assertNoDiagnostics()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `KMP project - when commonTest depends on kotlin-test - emits no diagnostics`() {
|
||||||
|
evaluateProjectAndResolveConfigurationsWhen {
|
||||||
|
kmpProjectWithJvm { sourceSets.commonTest.dependOnKotlinTest() }
|
||||||
|
}.assertNoDiagnostics()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `KMP project - when jvmMain depends on kotlin-test - emits a diagnostic`() {
|
||||||
|
evaluateProjectAndResolveConfigurationsWhen {
|
||||||
|
kmpProjectWithJvm { sourceSets.jvmMain.dependOnKotlinTest() }
|
||||||
|
}.checkDiagnostics("kotlin-test-kmp-jvmMain")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `KMP project - when commonMain depends on kotlin-test - emits a diagnostic`() {
|
||||||
|
evaluateProjectAndResolveConfigurationsWhen {
|
||||||
|
kmpProjectWithJvm { sourceSets.commonMain.dependOnKotlinTest() }
|
||||||
|
}.checkDiagnostics("kotlin-test-kmp-commonMain")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `KMP project without jvm - when commonMain depends on kotlin-test - emits no diagnostics`() {
|
||||||
|
evaluateProjectAndResolveConfigurationsWhen {
|
||||||
|
buildProjectWithMPP {
|
||||||
|
kotlin {
|
||||||
|
linuxArm64()
|
||||||
|
linuxX64()
|
||||||
|
|
||||||
|
sourceSets.commonMain.dependOnKotlinTest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.assertNoDiagnostics()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `JVM project - when testImplementation depends on kotlin-test - emits no diagnostics`() {
|
||||||
|
evaluateProjectAndResolveConfigurationsWhen {
|
||||||
|
buildProjectWithJvm {
|
||||||
|
dependencies {
|
||||||
|
"testImplementation"("org.jetbrains.kotlin:kotlin-test")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.assertNoDiagnostics()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `JVM project - when implementation depends on kotlin-test - emits a diagnostic`() {
|
||||||
|
evaluateProjectAndResolveConfigurationsWhen {
|
||||||
|
buildProjectWithJvm {
|
||||||
|
dependencies {
|
||||||
|
"implementation"("org.jetbrains.kotlin:kotlin-test")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.checkDiagnostics("kotlin-test-jvm-implementation")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun kmpProjectWithJvm(configure: KotlinMultiplatformExtension.() -> Unit): ProjectInternal {
|
||||||
|
return buildProjectWithMPP {
|
||||||
|
kotlin {
|
||||||
|
jvm()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
|
configure(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun NamedDomainObjectProvider<KotlinSourceSet>.dependOnKotlinTest() {
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("test"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun evaluateProjectAndResolveConfigurationsWhen(
|
||||||
|
projectFactory: () -> ProjectInternal
|
||||||
|
): ProjectInternal {
|
||||||
|
val project = projectFactory()
|
||||||
|
project.repositories.mavenLocal()
|
||||||
|
project.repositories.mavenCentralCacheRedirector()
|
||||||
|
project.evaluate()
|
||||||
|
project.configurations.filter(Configuration::isCanBeResolved).forEach(Configuration::resolve)
|
||||||
|
return project
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
[KotlinTestFrameworkInferenceFailed | WARNING] kotlin-test was added to a non-testing configuration "implementation" where test framework couldn't be inferred.
|
||||||
|
|
||||||
|
Learn how to configure kotlin-test at: https://kotl.in/kotlin-test-frameworks
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
[KotlinTestFrameworkInferenceFailed | WARNING] kotlin-test was added to a non-testing configuration "jvmCompilationImplementation" where test framework couldn't be inferred.
|
||||||
|
|
||||||
|
Learn how to configure kotlin-test at: https://kotl.in/kotlin-test-frameworks
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
[KotlinTestFrameworkInferenceFailed | WARNING] kotlin-test was added to a non-testing configuration "jvmMainImplementation" where test framework couldn't be inferred.
|
||||||
|
|
||||||
|
Learn how to configure kotlin-test at: https://kotl.in/kotlin-test-frameworks
|
||||||
|
----
|
||||||
|
[KotlinTestFrameworkInferenceFailed | WARNING] kotlin-test was added to a non-testing configuration "jvmCompilationImplementation" where test framework couldn't be inferred.
|
||||||
|
|
||||||
|
Learn how to configure kotlin-test at: https://kotl.in/kotlin-test-frameworks
|
||||||
Reference in New Issue
Block a user