-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure Gradle Integration tests to use Java Test Suites
- create a test suite for each project under test (helps with Gradle caching, task avoidance) - update CI/CD tasks to run specific test-suite tasks - disable integration test tasks due to dependency on Maven Local publishing (this will be fixed in an upcoming PR)
- Loading branch information
Showing
37 changed files
with
239 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,213 @@ | ||
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode | ||
|
||
/* | ||
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL | ||
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED | ||
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED | ||
import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP | ||
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Disabled | ||
|
||
plugins { | ||
id("dokkabuild.test-integration") | ||
id("dokkabuild.kotlin-jvm") | ||
`test-suite-base` | ||
`java-test-fixtures` | ||
} | ||
|
||
dependencies { | ||
implementation(projects.utilities) | ||
api(projects.utilities) | ||
|
||
api(libs.jsoup) | ||
|
||
implementation(kotlin("test-junit5")) | ||
implementation(libs.junit.jupiterApi) | ||
implementation(libs.junit.jupiterParams) | ||
api(libs.kotlin.test) | ||
api(libs.junit.jupiterApi) | ||
api(libs.junit.jupiterParams) | ||
|
||
implementation(gradleTestKit()) | ||
api(gradleTestKit()) | ||
} | ||
|
||
kotlin { | ||
explicitApi = Disabled | ||
|
||
implementation(libs.jsoup) | ||
compilerOptions { | ||
allWarningsAsErrors = false | ||
optIn.add("kotlin.io.path.ExperimentalPathApi") | ||
} | ||
} | ||
|
||
kotlin { | ||
// this project only contains test utils and isn't published, so it doesn't matter about explicit API | ||
explicitApi = ExplicitApiMode.Disabled | ||
explicitApi = Disabled | ||
} | ||
|
||
val aggregatingProject = gradle.includedBuild("dokka") | ||
|
||
tasks.integrationTest { | ||
tasks.integrationTestPreparation { | ||
dependsOn(aggregatingProject.task(":publishToMavenLocal")) | ||
} | ||
|
||
tasks.withType<Test>().configureEach { | ||
dependsOn(tasks.integrationTestPreparation) | ||
|
||
environment("DOKKA_VERSION", project.version) | ||
|
||
inputs.dir(file("projects")) | ||
maxHeapSize = "2G" | ||
|
||
val useK2 = dokkaBuild.integrationTestUseK2.get() | ||
|
||
useJUnitPlatform { | ||
if (useK2) excludeTags("onlyDescriptors", "onlyDescriptorsMPP") | ||
} | ||
|
||
systemProperty("org.jetbrains.dokka.experimental.tryK2", useK2) | ||
|
||
setForkEvery(1) | ||
dokkaBuild.integrationTestParallelism.orNull?.let { | ||
maxParallelForks = it | ||
} | ||
|
||
environment("isExhaustive", dokkaBuild.integrationTestExhaustive) | ||
|
||
// allow inspecting projects in temporary dirs after a test fails | ||
systemProperty( | ||
"junit.jupiter.tempdir.cleanup.mode.default", | ||
dokkaBuild.isCI.map { isCi -> if (isCi) "ALWAYS" else "ON_SUCCESS" }.get(), | ||
) | ||
|
||
testLogging { | ||
exceptionFormat = FULL | ||
events(SKIPPED, FAILED) | ||
showExceptions = true | ||
showCauses = true | ||
showStackTraces = true | ||
} | ||
|
||
doNotTrackState("uses artifacts from Maven Local") | ||
} | ||
|
||
val templateProjectsDir = layout.projectDirectory.dir("projects") | ||
|
||
@Suppress("UnstableApiUsage") | ||
testing { | ||
suites { | ||
withType<JvmTestSuite>().configureEach { | ||
useJUnitJupiter() | ||
|
||
dependencies { | ||
implementation(project()) | ||
} | ||
|
||
targets.configureEach { | ||
testTask.configure { | ||
doFirst { | ||
logger.lifecycle("running $path with javaLauncher:${javaLauncher.orNull?.metadata?.javaRuntimeVersion}") | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Create a new [JvmTestSuite] for a Gradle project. | ||
* | ||
* @param[projectPath] path to the Gradle project that will be tested by this suite, relative to [templateProjectsDir]. | ||
* The directory will be passed as a system property, `templateProjectDir`. | ||
*/ | ||
fun registerTestProjectSuite( | ||
name: String, | ||
projectPath: String, | ||
jvm: JavaLanguageVersion? = null, | ||
configure: JvmTestSuite.() -> Unit = {}, | ||
) { | ||
val templateProjectDir = templateProjectsDir.dir(projectPath) | ||
|
||
register<JvmTestSuite>(name) { | ||
targets.configureEach { | ||
testTask.configure { | ||
// Register the project dir as a specific input, so changes in other projects don't affect the caching of this test | ||
inputs.dir(templateProjectDir) | ||
// Pass the template dir in as a property, it is accessible in tests. | ||
systemProperty("templateProjectDir", templateProjectDir.asFile.invariantSeparatorsPath) | ||
|
||
if (jvm != null) { | ||
javaLauncher = javaToolchains.launcherFor { languageVersion = jvm } | ||
} | ||
} | ||
} | ||
configure() | ||
} | ||
} | ||
|
||
// register a separate test suite for each template project, to help with Gradle caching | ||
registerTestProjectSuite( | ||
"testTemplateProjectAndroid", | ||
"it-android-0", | ||
jvm = JavaLanguageVersion.of(11), // AGP requires JVM 11+ | ||
) | ||
registerTestProjectSuite("testTemplateProjectBasic", "it-basic") | ||
registerTestProjectSuite("testTemplateProjectBasicGroovy", "it-basic-groovy") | ||
registerTestProjectSuite("testTemplateProjectCollector", "it-collector-0") | ||
registerTestProjectSuite("testTemplateProjectConfiguration", "it-configuration") | ||
registerTestProjectSuite("testTemplateProjectJsIr", "it-js-ir-0") | ||
registerTestProjectSuite("testTemplateProjectMultimodule0", "it-multimodule-0") | ||
registerTestProjectSuite("testTemplateProjectMultimodule1", "it-multimodule-1") | ||
registerTestProjectSuite("testTemplateProjectMultimoduleVersioning", "it-multimodule-versioning-0") | ||
registerTestProjectSuite("testTemplateProjectMultiplatform", "it-multiplatform-0") | ||
registerTestProjectSuite("testTemplateProjectTasksExecutionStress", "it-sequential-tasks-execution-stress") | ||
registerTestProjectSuite("testTemplateProjectWasmBasic", "it-wasm-basic") | ||
registerTestProjectSuite("testTemplateProjectWasmJsWasiBasic", "it-wasm-js-wasi-basic") | ||
|
||
registerTestProjectSuite( | ||
"testExternalProjectKotlinxCoroutines", | ||
"coroutines/kotlinx-coroutines", | ||
jvm = JavaLanguageVersion.of(11) // kotlinx.coroutines requires JVM 11+ https://github.com/Kotlin/kotlinx.coroutines/issues/3665 | ||
) { | ||
targets.configureEach { | ||
testTask.configure { | ||
// register the whole directory as an input because it contains the git diff | ||
inputs.dir(templateProjectsDir.file("coroutines")) | ||
} | ||
} | ||
} | ||
registerTestProjectSuite("testExternalProjectKotlinxSerialization", "serialization/kotlinx-serialization") { | ||
targets.configureEach { | ||
testTask.configure { | ||
// register the whole directory as an input because it contains the git diff | ||
inputs.dir(templateProjectsDir.file("serialization")) | ||
} | ||
} | ||
} | ||
} | ||
tasks.check { | ||
dependsOn(suites) | ||
} | ||
} | ||
|
||
//region project tests management | ||
|
||
// set up task ordering - template projects (which are generally faster) should be tested before external projects | ||
val testTemplateProjectsTasks = tasks.withType<Test>().matching { it.name.startsWith("testTemplateProject") } | ||
val testExternalProjectsTasks = tasks.withType<Test>().matching { it.name.startsWith("testExternalProject") } | ||
|
||
testTemplateProjectsTasks.configureEach { | ||
shouldRunAfter(tasks.test) | ||
} | ||
testExternalProjectsTasks.configureEach { | ||
shouldRunAfter(tasks.test) | ||
shouldRunAfter(testTemplateProjectsTasks) | ||
} | ||
|
||
// define lifecycle tasks for project tests | ||
val testAllTemplateProjects by tasks.registering { | ||
description = "Lifecycle task for running all template-project tests" | ||
group = VERIFICATION_GROUP | ||
dependsOn(testTemplateProjectsTasks) | ||
doNotTrackState("lifecycle task, should always run") | ||
} | ||
|
||
javaLauncher.set(javaToolchains.launcherFor { | ||
// kotlinx.coroutines requires Java 11+ | ||
languageVersion.set(dokkaBuild.testJavaLauncherVersion.map { | ||
maxOf(it, JavaLanguageVersion.of(11)) | ||
}) | ||
}) | ||
val testAllExternalProjects by tasks.registering { | ||
description = "Lifecycle task for running all external-project tests" | ||
group = VERIFICATION_GROUP | ||
shouldRunAfter(testAllTemplateProjects) | ||
dependsOn(testExternalProjectsTasks) | ||
doNotTrackState("lifecycle task, should always run") | ||
} | ||
//endregion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.