[Build] Add jUnit dependencies in testApiJUnit5 to the implementation configuration

Adding these dependencies to the `api` configuration pollutes classpath for each dependant modules even if it doesn't need them. Instead, the dependencies should be declared more granularly if they're required
#KTI-1349 In Progress
This commit is contained in:
Alexander.Likhachev
2023-08-23 14:04:23 +02:00
committed by Space Team
parent 0ecbb64c64
commit 53fde520d5
45 changed files with 121 additions and 55 deletions
@@ -17,6 +17,8 @@ dependencies {
testImplementation(projectTests(":compiler:tests-common"))
testImplementation(projectTests(":compiler:tests-common-new"))
testImplementation(projectTests(":analysis:analysis-test-framework"))
testImplementation(libs.junit.jupyter.api)
testRuntimeOnly(libs.junit.jupyter.engine)
}
sourceSets {
@@ -24,7 +26,7 @@ sourceSets {
"test" { projectDefault() }
}
projectTest {
projectTest(jUnitMode = JUnitMode.JUnit5) {
workingDir = rootDir
}
@@ -18,6 +18,8 @@ dependencies {
testImplementation(projectTests(":compiler:tests-common"))
testImplementation(projectTests(":compiler:tests-common-new"))
testImplementation(projectTests(":analysis:decompiled:decompiler-to-file-stubs"))
testImplementation(libs.junit.jupyter.api)
testRuntimeOnly(libs.junit.jupyter.engine)
}
sourceSets {
@@ -25,7 +27,7 @@ sourceSets {
"test" { projectDefault() }
}
projectTest {
projectTest(jUnitMode = JUnitMode.JUnit5) {
workingDir = rootDir
}
@@ -23,6 +23,9 @@ dependencies {
api(project(":kotlin-util-klib-metadata"))
compileOnly(intellijCore())
testApi(platform(libs.junit.bom))
testImplementation(libs.junit4)
testCompileOnly(libs.junit.jupiter.api) // the annotations are misused and have no effect
testImplementation(projectTests(":compiler:tests-common"))
testImplementation(projectTests(":compiler:tests-common-new"))
testImplementation(projectTests(":analysis:decompiled:decompiler-to-file-stubs"))
@@ -24,6 +24,8 @@ dependencies {
testImplementation(projectTests(":analysis:analysis-api-fir"))
testImplementation(projectTests(":compiler:tests-common-new"))
testImplementation(projectTests(":analysis:low-level-api-fir"))
testImplementation(libs.junit.jupyter.api)
testRuntimeOnly(libs.junit.jupyter.engine)
}
sourceSets {
+1 -1
View File
@@ -25,7 +25,7 @@ dependencies {
testApi(projectTests(":compiler:tests-common"))
testApiJUnit5()
testImplementation(libs.junit.jupyter.params)
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(protobufFull())
testApi(kotlinStdlib())
testImplementation(project(":compiler:build-tools:kotlin-build-statistics"))
@@ -0,0 +1,56 @@
/*
* 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.util
/**
* A replacement for the JUnit Jupiter function to be used in JUnit 4 tests.
*
* Asserts that the given code block throws an exception of the specified type.
*
* @param E the type of exception that is expected to be thrown
* @param message the error message to be used if the exception is not thrown
* @param body the code block to be executed and verified
* @return the caught exception if it is of the specified type
* @throws AssertionError if the specified exception is not thrown
*/
inline fun <reified E : Exception> assertThrows(
message: String = "Expected ${E::class.java.name} to be thrown",
body: () -> Unit,
): Throwable {
try {
body()
} catch (e: Throwable) {
if (e is E) {
return e
}
}
throw AssertionError(message)
}
/**
* A replacement for the JUnit Jupiter function to be used in JUnit 4 tests.
*
* Asserts that the specified code block does not throw any exception.
*
* @param message The message to be included in the AssertionError if an exception is thrown.
* It can contain the "{}" placeholder, which will be replaced with the thrown exception.
* @param body The code block to be executed.
*
* @return The result of executing the code block.
*
* @throws AssertionError If the code block throws an exception.
*/
fun <R> assertDoesNotThrow(
message: String = "Expected no exception, but {} was thrown",
body: () -> R,
): R {
try {
return body()
} catch (e: Throwable) {
throw AssertionError(message.format(e))
}
}
+2 -2
View File
@@ -17,7 +17,7 @@ dependencies {
testApi(kotlinStdlib())
testApi(projectTests(":compiler:tests-common"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(projectTests(":compiler:test-infrastructure"))
testApi(projectTests(":compiler:test-infrastructure-utils"))
testApi(projectTests(":compiler:tests-compiler-utils"))
@@ -29,7 +29,7 @@ dependencies {
testRuntimeOnly(intellijCore())
testRuntimeOnly(commonDependency("org.jetbrains.intellij.deps.jna:jna"))
testApi(libs.junit.platform.launcher)
testImplementation(libs.junit.platform.launcher)
}
sourceSets {
+1 -1
View File
@@ -16,7 +16,7 @@ dependencies {
testApi(kotlinStdlib())
testApi(libs.junit4)
testImplementation(libs.junit4)
testCompileOnly(project(":kotlin-test:kotlin-test-jvm"))
testCompileOnly(project(":kotlin-test:kotlin-test-junit"))
testApi(projectTests(":compiler:tests-common"))
+1 -1
View File
@@ -37,7 +37,7 @@ dependencies {
testApi(project(":compiler:backend"))
testApi(project(":compiler:cli"))
testApi(projectTests(":compiler:tests-common"))
testApi(libs.junit4)
testImplementation(libs.junit4)
}
sourceSets {
+1 -1
View File
@@ -12,7 +12,7 @@ dependencies {
testCompileOnly("org.jetbrains:annotations:13.0")
testApi(project(":kotlin-test:kotlin-test-jvm"))
testApi(project(":kotlin-test:kotlin-test-junit"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testCompileOnly(intellijCore())
testRuntimeOnly(intellijCore())
@@ -13,7 +13,7 @@ plugins {
dependencies {
compileOnly(intellijCore())
testApi(libs.junit4)
testImplementation(libs.junit4)
testCompileOnly(project(":kotlin-test:kotlin-test-jvm"))
testCompileOnly(project(":kotlin-test:kotlin-test-junit"))
testApi(projectTests(":compiler:tests-common"))
@@ -18,7 +18,7 @@ dependencies {
testRuntimeOnly("xerces:xercesImpl:2.12.0")
testRuntimeOnly(commonDependency("commons-lang:commons-lang"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testCompileOnly(project(":kotlin-test:kotlin-test-jvm"))
testCompileOnly(project(":kotlin-test:kotlin-test-junit"))
testApi(projectTests(":compiler:tests-common"))
@@ -22,7 +22,7 @@ dependencies {
api(project(":compiler:build-tools:kotlin-build-tools-api"))
compileOnly(intellijCore())
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(project(":kotlin-test:kotlin-test-junit"))
testApi(kotlinStdlib())
testApi(projectTests(":kotlin-build-common"))
@@ -10,10 +10,8 @@ import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommo
import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.SourceFile.JavaSourceFile
import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.SourceFile.KotlinSourceFile
import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.TestSourceFile
import org.junit.Assert.assertEquals
import org.junit.Assert.*
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import java.io.File
private val testDataDir =
@@ -11,8 +11,8 @@ dependencies {
testApi(projectTests(":compiler:tests-common-new"))
testApiJUnit5()
testApi(libs.junit.platform.runner)
testApi(libs.junit.platform.suite.api)
testImplementation(libs.junit.platform.runner)
testImplementation(libs.junit.platform.suite.api)
runtimeOnly(libs.junit.vintage.engine)
testImplementation(intellijCore())
+1
View File
@@ -10,6 +10,7 @@ dependencies {
implementation(project(":compiler:ir.serialization.common"))
compileOnly(commonDependency("org.jetbrains.intellij.deps.fastutil:intellij-deps-fastutil"))
testApiJUnit5()
testImplementation(libs.junit.jupyter.params)
testImplementation(intellijCore())
testImplementation(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
testImplementation(projectTests(":compiler:tests-common-new"))
+1 -1
View File
@@ -8,7 +8,7 @@ dependencies {
testApi(project(":core:util.runtime"))
testApi(projectTests(":compiler:test-infrastructure-utils"))
testApi(kotlinStdlib())
testApi(libs.junit4)
testImplementation(libs.junit4)
testApiJUnit5()
testApi(project(":generators"))
+1 -1
View File
@@ -55,7 +55,7 @@ dependencies {
testApi(project(":js:js.dce"))
testApi(project(":js:js.engines"))
testApi(project(":compiler:incremental-compilation-impl"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(projectTests(":kotlin-build-common"))
testApi(projectTests(":generators:test-generator"))
@@ -10,7 +10,7 @@ dependencies {
testRuntimeOnly(project(":kotlin-scripting-compiler-embeddable"))
testRuntimeOnly(project(":kotlin-scripting-jvm-host"))
testRuntimeOnly(libs.guava)
testApi(libs.junit4)
testImplementation(libs.junit4)
}
sourceSets {
@@ -12,7 +12,7 @@ dependencies {
testRuntimeOnly(project(":kotlin-compiler"))
testRuntimeOnly(project(":kotlin-scripting-compiler"))
testApi(libs.junit4)
testImplementation(libs.junit4)
}
sourceSets {
@@ -8,7 +8,7 @@ dependencies {
api(project(":kotlin-scripting-jvm-host-unshaded"))
testRuntimeOnly(project(":kotlin-compiler"))
testRuntimeOnly(project(":kotlin-scripting-compiler"))
testApi(libs.junit4)
testImplementation(libs.junit4)
}
sourceSets {
+1 -1
View File
@@ -8,7 +8,7 @@ project.updateJvmTarget("1.8")
dependencies {
api(kotlinStdlib())
compileOnly(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
testApi(libs.junit4)
testImplementation(libs.junit4)
}
sourceSets {
@@ -8,7 +8,7 @@ project.updateJvmTarget("1.8")
dependencies {
api(kotlinStdlib())
api(project(":kotlin-scripting-common"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testImplementation(commonDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
}
@@ -17,7 +17,7 @@ val testJsr223Runtime by configurations.creating {
val testCompilationClasspath by configurations.creating
dependencies {
testApi(libs.junit4)
testImplementation(libs.junit4)
testCompileOnly(project(":kotlin-scripting-jvm-host-unshaded"))
testCompileOnly(project(":compiler:cli"))
testCompileOnly(project(":core:util.runtime"))
+1 -1
View File
@@ -9,7 +9,7 @@ dependencies {
api(project(":kotlin-script-runtime"))
api(kotlinStdlib())
api(project(":kotlin-scripting-common"))
testApi(libs.junit4)
testImplementation(libs.junit4)
}
sourceSets {
@@ -14,8 +14,8 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers.resolveMetadata
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution
import org.jetbrains.kotlin.gradle.util.*
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import org.jetbrains.kotlin.util.assertDoesNotThrow
import org.jetbrains.kotlin.util.assertThrows
import kotlin.test.Test
class StdlibJsExplicitDependencyResolutionTest {
@@ -17,8 +17,8 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.Stage.ReadyForEx
import org.jetbrains.kotlin.gradle.util.buildProject
import org.jetbrains.kotlin.gradle.util.runLifecycleAwareTest
import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.util.assertThrows
import org.junit.Test
import org.junit.jupiter.api.assertThrows
import java.util.concurrent.atomic.AtomicInteger
import kotlin.test.*
@@ -11,9 +11,9 @@ import com.intellij.util.io.Compressor
import org.gradle.kotlin.dsl.support.unzipTo
import org.jetbrains.kotlin.gradle.utils.copyZipFilePartially
import org.jetbrains.kotlin.gradle.utils.listDescendants
import org.jetbrains.kotlin.util.assertThrows
import org.junit.Rule
import org.junit.Test
import org.junit.jupiter.api.assertThrows
import org.junit.rules.TemporaryFolder
import java.io.File
import java.util.zip.ZipEntry
@@ -9,14 +9,12 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.statistics.metrics.StringAnonymizationPolicy
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
import org.junit.jupiter.api.DisplayName
import kotlin.test.Test
class KotlinBuildStatHandlerTest {
@DisplayName("Checks that all KonanTarget names are presented in MPP_PLATFORMS statistic's report validator")
@Test
fun mppPlatformsShouldContainsllKonanTargetsTest() {
@Test // Checks that all KonanTarget names are presented in MPP_PLATFORMS statistic's report validator
fun mppPlatformsShouldContainAllKonanTargetsTest() {
val regex = Regex(StringMetrics.MPP_PLATFORMS.anonymization.validationRegexp())
val konanTargetsMissedInMppPlatforms = KonanTarget::class.sealedSubclasses
@@ -28,8 +26,7 @@ class KotlinBuildStatHandlerTest {
}
}
@DisplayName("Checks that all KotlinPlatformType names are presented in MPP_PLATFORMS statistic's report validator")
@Test
@Test // Checks that all KotlinPlatformType names are presented in MPP_PLATFORMS statistic's report validator
fun mppPlatformsShouldContainAllKotlinPlatformTypeTest() {
val regex = Regex(StringMetrics.MPP_PLATFORMS.anonymization.validationRegexp())
@@ -43,8 +40,7 @@ class KotlinBuildStatHandlerTest {
}
@DisplayName("Checks that only values listed in KotlinPlatformType and KonanTarget are included in MPP_PLATFORMS")
@Test
@Test // Checks that only values listed in KotlinPlatformType and KonanTarget are included in MPP_PLATFORMS
fun mppPlatformsShouldContainOnlyKonanTargetsAndKotlinPlatformTypeTest() {
val allowedMppValues =
(StringMetrics.MPP_PLATFORMS.anonymization as StringAnonymizationPolicy.AllowedListAnonymizer)
@@ -15,8 +15,8 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsDefault
import org.jetbrains.kotlin.gradle.utils.newInstance
import org.jetbrains.kotlin.testhelpers.StubLogger
import org.jetbrains.kotlin.util.assertThrows
import org.junit.Before
import org.junit.jupiter.api.assertThrows
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -6,8 +6,8 @@
package org.jetbrains.kotlin.gradle.utils
import org.jetbrains.kotlin.gradle.plugin.MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING
import org.jetbrains.kotlin.util.assertThrows
import org.junit.AssumptionViolatedException
import org.junit.jupiter.api.assertThrows
import java.net.URLClassLoader
import kotlin.test.Test
import kotlin.test.assertNull
@@ -49,7 +49,7 @@ class CastIsolatedKotlinPluginClassLoaderAwareTest {
assertTrue(
MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING !in exception.message.orEmpty(),
"Expected no classpath warning in the error message, since this cast was not failing because of iosolated classloaders"
"Expected no classpath warning in the error message, since this cast was not failing because of isolated classloaders"
)
}
@@ -12,7 +12,7 @@ dependencies {
testCompileOnly(project(":compiler:cli"))
testCompileOnly(project(":kotlin-scripting-jvm-host-unshaded"))
testApi(kotlinStdlib("jdk8"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(projectTests(":kotlin-scripting-compiler")) { isTransitive = false }
testImplementation(project(":kotlin-compiler-embeddable"))
kotlinxSerializationGradlePluginClasspath(project(":kotlinx-serialization-compiler-plugin.embeddable")) { isTransitive = false }
@@ -17,7 +17,7 @@ dependencies {
api(project(":kotlin-daemon-client"))
testCompileOnly(project(":compiler:cli"))
testApi(project(":kotlin-test:kotlin-test-junit"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(project(":kotlin-scripting-compiler"))
testRuntimeOnly(project(":kotlin-compiler"))
testApi(intellijCore())
@@ -37,7 +37,7 @@ dependencies {
testApi(project(":kotlin-android-extensions-runtime"))
testApi(projectTests(":compiler:tests-common"))
testApi(project(":kotlin-test:kotlin-test-jvm"))
testApi(libs.junit4)
testImplementation(libs.junit4)
robolectricDependency("org.robolectric:android-all:5.0.2_r3-robolectric-r0")
+2 -1
View File
@@ -20,12 +20,13 @@ dependencies {
testApi(projectTests(":compiler:tests-common-new"))
testImplementation(projectTests(":compiler:tests-common"))
testImplementation(libs.junit4)
testImplementation(libs.junit.jupyter.api)
testCompileOnly(project(":kotlin-reflect-api"))
testRuntimeOnly(project(":kotlin-reflect"))
testRuntimeOnly(project(":core:descriptors.runtime"))
testRuntimeOnly(project(":compiler:fir:fir-serialization"))
testRuntimeOnly(libs.junit.jupyter.engine)
testApi(intellijCore())
}
@@ -83,7 +83,7 @@ dependencies {
testImplementation(projectTests(":generators:test-generator"))
testImplementation(projectTests(":js:js.tests"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(project(":kotlin-test:kotlin-test-jvm"))
// Dependencies for Kotlin/Native test infra:
@@ -9,6 +9,7 @@ dependencies {
testApi(project(":plugins:fir-plugin-prototype"))
testApi(project(":compiler:incremental-compilation-impl"))
testApi(projectTests(":compiler:incremental-compilation-impl"))
testImplementation(libs.junit.jupyter.api)
testCompileOnly(intellijCore())
+3 -1
View File
@@ -28,6 +28,7 @@ dependencies {
testApi(projectTests(":compiler:tests-common-new"))
testApi(projectTests(":compiler:test-infrastructure"))
testApi(projectTests(":compiler:test-infrastructure-utils"))
testImplementation(libs.junit.jupyter.api)
// FIR dependencies
testApi(project(":compiler:fir:checkers"))
@@ -35,8 +36,9 @@ dependencies {
testRuntimeOnly(project(":compiler:fir:fir-serialization"))
testRuntimeOnly(project(":core:descriptors.runtime"))
testRuntimeOnly(libs.junit.jupyter.engine)
testApi(libs.junit4)
testImplementation(libs.junit4)
testRuntimeOnly(libs.guava)
testRuntimeOnly(commonDependency("org.codehaus.woodstox:stax2-api"))
@@ -53,7 +53,7 @@ dependencies {
testRuntimeOnly(commonDependency("com.fasterxml:aalto-xml"))
testRuntimeOnly("com.jetbrains.intellij.platform:util-xml-dom:$intellijVersion") { isTransitive = false }
testApi(libs.junit4)
testImplementation(libs.junit4)
robolectricDependency("org.robolectric:android-all:5.0.2_r3-robolectric-r0")
@@ -32,7 +32,7 @@ dependencies {
testApi(project(":compiler:cli-common"))
testApi(project(":compiler:frontend.java"))
testApi(projectTests(":compiler:tests-common"))
testApi(libs.junit4)
testImplementation(libs.junit4)
}
sourceSets {
@@ -32,7 +32,7 @@ dependencies {
testApi(project(":compiler:cli-common"))
testApi(project(":compiler:frontend.java"))
testApi(projectTests(":compiler:tests-common"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testImplementation(intellijCore())
testImplementation(commonDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
@@ -21,7 +21,7 @@ dependencies {
testApi(project(":compiler:cli-common"))
testApi(project(":daemon-common"))
testApi(project(":kotlin-daemon-client"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(project(":kotlin-test:kotlin-test-jvm"))
testApi(project(":kotlin-test:kotlin-test-junit"))
testCompilerClasspath(project(":kotlin-compiler"))
+1 -1
View File
@@ -22,7 +22,7 @@ dependencies {
runtimeOnly(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
runtimeOnly(project(":kotlin-daemon-embeddable"))
runtimeOnly(commonDependency("org.jetbrains.intellij.deps", "trove4j"))
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(project(":kotlin-test:kotlin-test-junit"))
testCompilationClasspath(kotlinStdlib())
}
@@ -197,13 +197,13 @@ fun Project.testApiJUnit5() {
with(dependencies) {
val libsVersionCatalog = libsVersionCatalog
testApi(platform(libsVersionCatalog.findLibrary("junit-bom").orElseThrow { GradleException("No version for `junit-bom`") }))
testApi(libsVersionCatalog.findLibrary("junit-jupyter-api").orElseThrow { GradleException("No version for `junit-jupyter-api`") })
testImplementation(libsVersionCatalog.findLibrary("junit-jupyter-api").orElseThrow { GradleException("No version for `junit-jupyter-api`") })
testRuntimeOnly(
libsVersionCatalog.findLibrary("junit-jupyter-engine").orElseThrow { GradleException("No version for `junit-jupyter-engine`") })
testApi(
testImplementation(
libsVersionCatalog.findLibrary("junit-platform-commons")
.orElseThrow { GradleException("No version for `junit-platform-commons`") })
testApi(
testImplementation(
libsVersionCatalog.findLibrary("junit-platform-launcher")
.orElseThrow { GradleException("No version for `junit-platform-launcher`") })
}
+3 -1
View File
@@ -61,10 +61,12 @@ val jsShell by configurations.creating {
}
dependencies {
testApi(libs.junit4)
testImplementation(libs.junit4)
testApi(projectTests(":compiler:tests-common"))
testApi(projectTests(":compiler:tests-common-new"))
testApi(intellijCore())
testImplementation(libs.junit.jupyter.api)
testRuntimeOnly(libs.junit.jupyter.engine)
jsShell("org.mozilla:jsshell:$jsShellVersion:$jsShellSuffix@zip")