diff --git a/.github/workflows/preview-publish-ga.yml b/.github/workflows/preview-publish-ga.yml index 323641a01c..64d64fcb33 100644 --- a/.github/workflows/preview-publish-ga.yml +++ b/.github/workflows/preview-publish-ga.yml @@ -25,7 +25,7 @@ jobs: uses: gradle/gradle-build-action@v2 with: gradle-home-cache-cleanup: true - arguments: :dokka-integration-tests:gradle:integrationTest --tests org.jetbrains.dokka.it.gradle.kotlin.CoroutinesGradleIntegrationTest --stacktrace "-Dorg.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=500m" + arguments: :dokka-integration-tests:gradle:testExternalProjectKotlinxCoroutines --stacktrace "-Dorg.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=500m" env: DOKKA_TEST_OUTPUT_PATH: /home/runner/work/dokka/coroutines - name: Copy files to GitHub Actions Artifacts @@ -52,7 +52,7 @@ jobs: uses: gradle/gradle-build-action@v2 with: gradle-home-cache-cleanup: true - arguments: :dokka-integration-tests:gradle:integrationTest --tests org.jetbrains.dokka.it.gradle.kotlin.SerializationGradleIntegrationTest --stacktrace "-Dorg.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=500m" + arguments: :dokka-integration-tests:gradle:testExternalProjectKotlinxSerialization --stacktrace "-Dorg.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=500m" env: DOKKA_TEST_OUTPUT_PATH: /home/runner/work/dokka/serialization - name: Copy files to GitHub Actions Artifacts diff --git a/.github/workflows/preview-publish-web-s3.yml b/.github/workflows/preview-publish-web-s3.yml index 5c5f1db2dd..f0ecd25c49 100644 --- a/.github/workflows/preview-publish-web-s3.yml +++ b/.github/workflows/preview-publish-web-s3.yml @@ -22,7 +22,7 @@ jobs: uses: gradle/gradle-build-action@v2 with: gradle-home-cache-cleanup: true - arguments: :dokka-integration-tests:gradle:integrationTest --tests org.jetbrains.dokka.it.gradle.kotlin.CoroutinesGradleIntegrationTest --stacktrace "-Dorg.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=500m" + arguments: :dokka-integration-tests:gradle:testExternalProjectKotlinxCoroutines --stacktrace "-Dorg.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=500m" env: DOKKA_TEST_OUTPUT_PATH: /home/runner/work/dokka/coroutines - name: Configure AWS credentials for S3 access @@ -36,7 +36,7 @@ jobs: - name: Print link run: echo https://dokka-snapshots.s3.eu-central-1.amazonaws.com/${{ env.branch-name }}/coroutines/${GITHUB_SHA::7}/index.html - kotilnx-serialization: + kotlinx-serialization: runs-on: ubuntu-latest if: github.repository == 'Kotlin/dokka' steps: @@ -51,7 +51,7 @@ jobs: uses: gradle/gradle-build-action@v2 with: gradle-home-cache-cleanup: true - arguments: :dokka-integration-tests:gradle:integrationTest --tests org.jetbrains.dokka.it.gradle.kotlin.SerializationGradleIntegrationTest --stacktrace "-Dorg.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=500m" + arguments: :dokka-integration-tests:gradle:testExternalProjectKotlinxSerialization --stacktrace "-Dorg.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=500m" env: DOKKA_TEST_OUTPUT_PATH: /home/runner/work/dokka/serialization - name: Configure AWS credentials for S3 access diff --git a/.github/workflows/tests-thorough.yml b/.github/workflows/tests-thorough.yml index 8450fa6b9b..c431f524cb 100644 --- a/.github/workflows/tests-thorough.yml +++ b/.github/workflows/tests-thorough.yml @@ -30,11 +30,11 @@ jobs: # Running tests with the Gradle daemon on windows agents leads to some very strange # JVM crashes for some reason. Most likely a problem of Gradle/GitHub/Windows server run: > - ./gradlew test --stacktrace --no-daemon --no-parallel + ./gradlew test --stacktrace --no-daemon --no-parallel --continue "-Dorg.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=500m" "-Porg.jetbrains.dokka.javaToolchain.testLauncher=${{ matrix.javaVersion }}" - name: Run tests under Ubuntu/Macos if: matrix.os != 'windows-latest' run: > - ./gradlew test --stacktrace + ./gradlew test --stacktrace --continue "-Porg.jetbrains.dokka.javaToolchain.testLauncher=${{ matrix.javaVersion }}" diff --git a/build-logic/src/main/kotlin/dokkabuild.base.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.base.gradle.kts index 4c70ddcf58..b456893de3 100644 --- a/build-logic/src/main/kotlin/dokkabuild.base.gradle.kts +++ b/build-logic/src/main/kotlin/dokkabuild.base.gradle.kts @@ -1,7 +1,6 @@ /* * Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ - import dokkabuild.DokkaBuildProperties import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP diff --git a/build-logic/src/main/kotlin/dokkabuild.setup-maven-cli.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.setup-maven-cli.gradle.kts index 96812e4c60..9ef7cac2ab 100644 --- a/build-logic/src/main/kotlin/dokkabuild.setup-maven-cli.gradle.kts +++ b/build-logic/src/main/kotlin/dokkabuild.setup-maven-cli.gradle.kts @@ -84,7 +84,6 @@ val installMavenBinary by tasks.registering(Sync::class) { val archives = serviceOf() from( mavenBinary.flatMap { conf -> - @Suppress("UnstableApiUsage") val resolvedArtifacts = conf.incoming.artifacts.resolvedArtifacts resolvedArtifacts.map { artifacts -> diff --git a/build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt b/build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt index 311a384566..c145a285e9 100644 --- a/build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt +++ b/build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt @@ -4,10 +4,12 @@ package dokkabuild +import org.gradle.api.file.ProjectLayout import org.gradle.api.provider.Provider import org.gradle.api.provider.ProviderFactory import org.gradle.jvm.toolchain.JavaLanguageVersion import org.jetbrains.kotlin.gradle.dsl.KotlinVersion +import java.io.File import javax.inject.Inject /** @@ -20,8 +22,22 @@ import javax.inject.Inject */ abstract class DokkaBuildProperties @Inject constructor( private val providers: ProviderFactory, + private val layout: ProjectLayout, ) { + private val buildingOnTeamCity: Provider = + providers.environmentVariable("TEAMCITY_VERSION").map(String::isNotBlank) + + private val buildingOnGitHub: Provider = + providers.environmentVariable("GITHUB_ACTION").map(String::isNotBlank) + + val isCI: Provider = + providers.environmentVariable("CI") + .map(String::isNotBlank) + .orElse(buildingOnTeamCity) + .orElse(buildingOnGitHub) + .orElse(false) + /** * The main version of Java that should be used to build Dokka source code. * @@ -62,6 +78,20 @@ abstract class DokkaBuildProperties @Inject constructor( dokkaProperty("integration_test.useK2", String::toBoolean) .orElse(false) + val androidSdkDir: Provider = + providers + // first try finding a local.properties file in any parent directory + .provider { + generateSequence(layout.projectDirectory.asFile, File::getParentFile) + .mapNotNull { dir -> dir.resolve("local.properties").takeIf(File::exists) } + .flatMap { file -> file.readLines().filter { it.startsWith("sdk.dir=") } } + .firstOrNull() + ?.substringAfter("sdk.dir=") + } + // else try getting pre-installed SDK (e.g. via GitHub step setup-android) + .orElse(providers.environmentVariable("ANDROID_SDK_ROOT")) + .orElse(providers.environmentVariable("ANDROID_HOME")) + .map(::File) private fun dokkaProperty(name: String, convert: (String) -> T) = providers.gradleProperty("org.jetbrains.dokka.$name").map(convert) diff --git a/build-logic/src/main/kotlin/dokkabuild/tasks/GitCheckoutTask.kt b/build-logic/src/main/kotlin/dokkabuild/tasks/GitCheckoutTask.kt index f1fe4c667f..0aee4ee1f6 100644 --- a/build-logic/src/main/kotlin/dokkabuild/tasks/GitCheckoutTask.kt +++ b/build-logic/src/main/kotlin/dokkabuild/tasks/GitCheckoutTask.kt @@ -67,7 +67,7 @@ abstract class GitCheckoutTask @Inject constructor( exclude(".git/") } - logger.lifecycle("initialized git repo $uri in ${destination.asFile.orNull}") + logger.lifecycle("initialized git repo ${uri.get()} in ${destination.asFile.get()}") } /** diff --git a/dokka-integration-tests/gradle/README.md b/dokka-integration-tests/gradle/README.md index e0c511e16d..5d2755f9c3 100644 --- a/dokka-integration-tests/gradle/README.md +++ b/dokka-integration-tests/gradle/README.md @@ -14,7 +14,7 @@ Integration tests have fixed git revision number, with the diff patch applied fr In order to update: -* Checkout the project with the requered revision +* Checkout the project with the required revision - It's some state of the `master` * Manually write the diff (or apply the existing one and tweak) to have the project buildable against locally published Dokka of version `for-integration-tests-SNAPSHOT` * `git diff > $pathToProjectInDokka/project.diff` @@ -26,4 +26,4 @@ In order to update: ### Run integration tests with K2 (symbols) To run integration tests with K2, the property `org.jetbrains.dokka.integration_test.useK2` should be set to `true`. -By default, the task `integrationTest` is run with K1 (descriptors). +By default, the integration tests are run with K1 (descriptors). diff --git a/dokka-integration-tests/gradle/build.gradle.kts b/dokka-integration-tests/gradle/build.gradle.kts index d454b14515..797991c7df 100644 --- a/dokka-integration-tests/gradle/build.gradle.kts +++ b/dokka-integration-tests/gradle/build.gradle.kts @@ -1,52 +1,246 @@ /* * Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ +@file:Suppress("UnstableApiUsage") + import dokkabuild.tasks.GitCheckoutTask -import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode +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") + `jvm-test-suite` + `java-test-fixtures` } dependencies { - implementation(projects.utilities) + api(projects.utilities) - implementation(kotlin("test-junit5")) - implementation(libs.junit.jupiterApi) - implementation(libs.junit.jupiterParams) + api(libs.jsoup) - implementation(gradleTestKit()) + api(libs.kotlin.test) + api(libs.junit.jupiterApi) + api(libs.junit.jupiterParams) - implementation(libs.jsoup) + api(gradleTestKit()) } 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 templateProjectsDir = layout.projectDirectory.dir("projects") + compilerOptions { + optIn.add("kotlin.io.path.ExperimentalPathApi") + } +} val aggregatingProject = gradle.includedBuild("dokka") +val templateProjectsDir = layout.projectDirectory.dir("projects") -tasks.integrationTest { +tasks.integrationTestPreparation { + // TODO remove this in https://github.com/Kotlin/dokka/pull/3433 dependsOn(aggregatingProject.task(":publishToMavenLocal")) - dependsOn( - checkoutKotlinxCoroutines, - checkoutKotlinxSerialization, +} + +tasks.withType().configureEach { + dependsOn(tasks.integrationTestPreparation) + + setForkEvery(1) + maxHeapSize = "2G" + dokkaBuild.integrationTestParallelism.orNull?.let { parallelism -> + maxParallelForks = parallelism + } + + val useK2 = dokkaBuild.integrationTestUseK2.get() + + useJUnitPlatform { + if (useK2) excludeTags("onlyDescriptors", "onlyDescriptorsMPP") + } + + systemProperty("org.jetbrains.dokka.experimental.tryK2", useK2) + // 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(), ) environment("DOKKA_VERSION", project.version) - inputs.dir(templateProjectsDir) + // environment() isn't Provider API compatible yet https://github.com/gradle/gradle/issues/11534 + dokkaBuild.integrationTestExhaustive.orNull?.let { exhaustive -> + environment("isExhaustive", exhaustive) + } + dokkaBuild.androidSdkDir.orNull?.let { androidSdkDir -> + environment("ANDROID_HOME", androidSdkDir.invariantSeparatorsPath) + } + + testLogging { + exceptionFormat = FULL + events(SKIPPED, FAILED) + showExceptions = true + showCauses = true + showStackTraces = true + } + + // TODO remove this in https://github.com/Kotlin/dokka/pull/3433 + doNotTrackState("uses artifacts from Maven Local") +} + +testing { + suites { + withType().configureEach { + useJUnitJupiter() + + dependencies { + // test suites are independent by default (unlike the test source set), and must manually depend on the project + implementation(project()) + } + + targets.configureEach { + testTask.configure { + doFirst { + logger.info("running $path with javaLauncher:${javaLauncher.orNull?.metadata?.javaRuntimeVersion}") + } + } + } + } + + // register a separate test suite for each 'template' project + 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("testTemplateProjectMultimoduleInterModuleLinks", "it-multimodule-inter-module-links") + 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 { + dependsOn(checkoutKotlinxCoroutines) + // register the whole directory as an input because it contains the git diff + inputs + .dir(templateProjectsDir.file("coroutines")) + .withPropertyName("coroutinesProjectDir") + } + } + } + registerTestProjectSuite( + "testExternalProjectKotlinxSerialization", + "serialization/kotlinx-serialization", + jvm = JavaLanguageVersion.of(11) // https://github.com/Kotlin/kotlinx.serialization/blob/1116f5f13a957feecda47d5e08b0aa335fc010fa/gradle/configure-source-sets.gradle#L9 + ) { + targets.configureEach { + testTask.configure { + dependsOn(checkoutKotlinxSerialization) + // register the whole directory as an input because it contains the git diff + inputs + .dir(templateProjectsDir.file("serialization")) + .withPropertyName("serializationProjectDir") + } + } + } + } + tasks.check { + dependsOn(suites) + } +} + + +/** + * 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 TestingExtension.registerTestProjectSuite( + name: String, + projectPath: String, + jvm: JavaLanguageVersion? = null, + configure: JvmTestSuite.() -> Unit = {}, +) { + val templateProjectDir = templateProjectsDir.dir(projectPath) + + suites.register(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).withPropertyName("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 } + } + + // For validation, on CI the generated output is uploaded, so the test must produce output in + // DOKKA_TEST_OUTPUT_PATH. For Gradle up-to-date checks the output dir must be specified. + val testOutputPath = System.getenv("DOKKA_TEST_OUTPUT_PATH") + inputs.property("testOutputPath", testOutputPath).optional(true) + if (testOutputPath != null) { + outputs.dir(testOutputPath).withPropertyName("testOutput") + } + } + } + configure() + } +} + +//region project tests management + +// set up task ordering - template projects (which are generally faster) should be tested before external projects +val testTemplateProjectsTasks = tasks.withType().matching { it.name.startsWith("testTemplateProject") } +val testExternalProjectsTasks = tasks.withType().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") +} + +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") +} - javaLauncher.set(javaToolchains.launcherFor { - // kotlinx.coroutines requires Java 11+ - languageVersion.set(dokkaBuild.testJavaLauncherVersion.map { - maxOf(it, JavaLanguageVersion.of(11)) - }) - }) +val integrationTest by tasks.registering { + description = "Lifecycle task for running integration tests" + // TODO - Refactor Maven and CLI integration tests to use Test Suites + // - Reimplement dokkabuild.test-integration.gradle.kts so that `integrationTest` is defined once there + dependsOn(tasks.withType()) // all tests in this project are integration tests } +//endregion val checkoutKotlinxCoroutines by tasks.registering(GitCheckoutTask::class) { uri = "https://github.com/Kotlin/kotlinx.coroutines.git" diff --git a/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt index 0e44648343..7d204d3622 100644 --- a/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt +++ b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleIntegrationTest.kt @@ -6,7 +6,6 @@ package org.jetbrains.dokka.it.gradle import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner -import org.gradle.testkit.runner.internal.DefaultGradleRunner import org.gradle.tooling.GradleConnectionException import org.gradle.util.GradleVersion import org.jetbrains.dokka.it.AbstractIntegrationTest @@ -56,8 +55,7 @@ abstract class AbstractGradleIntegrationTest : AbstractIntegrationTest() { * arguments ) - ).run { this as DefaultGradleRunner } - .withJvmArguments(jvmArgs) + ).withJvmArguments(jvmArgs) } fun GradleRunner.buildRelaxed(): BuildResult { diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/TestedVersions.kt b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/TestedVersions.kt similarity index 91% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/TestedVersions.kt rename to dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/TestedVersions.kt index fd3a829a11..15c72138e3 100644 --- a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/TestedVersions.kt +++ b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/TestedVersions.kt @@ -9,10 +9,10 @@ import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.ArgumentsProvider import java.util.stream.Stream -internal class LatestTestedVersionsArgumentsProvider : TestedVersionsArgumentsProvider(listOf(TestedVersions.LATEST)) -internal open class AllSupportedTestedVersionsArgumentsProvider : TestedVersionsArgumentsProvider(TestedVersions.ALL_SUPPORTED) +class LatestTestedVersionsArgumentsProvider : TestedVersionsArgumentsProvider(listOf(TestedVersions.LATEST)) +open class AllSupportedTestedVersionsArgumentsProvider : TestedVersionsArgumentsProvider(TestedVersions.ALL_SUPPORTED) -internal object TestedVersions { +object TestedVersions { val LATEST = BuildVersions("7.6.2", "1.9.22") diff --git a/dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/gradleRunnerUtils.kt b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/gradleRunnerUtils.kt similarity index 62% rename from dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/gradleRunnerUtils.kt rename to dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/gradleRunnerUtils.kt index 912d1df17b..89693a62cd 100644 --- a/dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/gradleRunnerUtils.kt +++ b/dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/gradleRunnerUtils.kt @@ -1,4 +1,7 @@ -package org.jetbrains.dokka.dokkatoo.utils +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ +package org.jetbrains.dokka.it.gradle import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.BuildTask @@ -9,25 +12,26 @@ import org.gradle.testkit.runner.internal.DefaultGradleRunner /** Edit environment variables in the Gradle Runner */ @Deprecated("Windows does not support withEnvironment - https://github.com/gradle/gradle/issues/23959") fun GradleRunner.withEnvironment(build: MutableMap.() -> Unit): GradleRunner { - val env = environment ?: mutableMapOf() - env.build() - return withEnvironment(env) + val env = environment ?: mutableMapOf() + env.build() + return withEnvironment(env) } inline fun GradleRunner.build( - handleResult: BuildResult.() -> Unit + handleResult: BuildResult.() -> Unit ): Unit = build().let(handleResult) inline fun GradleRunner.buildAndFail( - handleResult: BuildResult.() -> Unit + handleResult: BuildResult.() -> Unit ): Unit = buildAndFail().let(handleResult) +// workaround for https://github.com/gradle/gradle/issues/1043 fun GradleRunner.withJvmArguments( - vararg jvmArguments: String -): GradleRunner = (this as DefaultGradleRunner).withJvmArguments(*jvmArguments) + jvmArguments: Collection +): GradleRunner = (this as DefaultGradleRunner).withJvmArguments(*jvmArguments.toTypedArray()) /** @@ -35,13 +39,13 @@ fun GradleRunner.withJvmArguments( * [GradleRunner arguments][GradleRunner.getArguments]. */ fun GradleRunner.addArguments( - vararg arguments: String + vararg arguments: String ): GradleRunner = - withArguments(this@addArguments.arguments + arguments) + withArguments(this@addArguments.arguments + arguments) /** * Get the name of the task, without the leading [BuildTask.getPath]. */ val BuildTask.name: String - get() = path.substringAfterLast(':') + get() = path.substringAfterLast(':') diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/StdLibDocumentationIntegrationTest.kt b/dokka-integration-tests/gradle/src/test/kotlin/StdLibDocumentationIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/StdLibDocumentationIntegrationTest.kt rename to dokka-integration-tests/gradle/src/test/kotlin/StdLibDocumentationIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/kotlin/CoroutinesGradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/testExternalProjectKotlinxCoroutines/kotlin/CoroutinesGradleIntegrationTest.kt similarity index 93% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/kotlin/CoroutinesGradleIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testExternalProjectKotlinxCoroutines/kotlin/CoroutinesGradleIntegrationTest.kt index 8ef056c3a2..ab4b357414 100644 --- a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/kotlin/CoroutinesGradleIntegrationTest.kt +++ b/dokka-integration-tests/gradle/src/testExternalProjectKotlinxCoroutines/kotlin/CoroutinesGradleIntegrationTest.kt @@ -53,7 +53,10 @@ class CoroutinesGradleIntegrationTest : AbstractGradleIntegrationTest(), TestOut val result = createGradleRunner( buildVersions, ":dokkaHtmlMultiModule", "-i", "-s", - jvmArgs = listOf("-Xmx2G", "-XX:MaxMetaspaceSize=500m") + jvmArgs = listOf( + "-Xmx2G", + "-XX:MaxMetaspaceSize=500m", // Intentionally small to verify that Dokka tasks do not cause leaks. + ) ).buildRelaxed() assertEquals(TaskOutcome.SUCCESS, assertNotNull(result.task(":dokkaHtmlMultiModule")).outcome) diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/kotlin/SerializationGradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/testExternalProjectKotlinxSerialization/kotlin/SerializationGradleIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/kotlin/SerializationGradleIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testExternalProjectKotlinxSerialization/kotlin/SerializationGradleIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Android0GradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectAndroid/kotlin/Android0GradleIntegrationTest.kt similarity index 99% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Android0GradleIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectAndroid/kotlin/Android0GradleIntegrationTest.kt index b00e05e3e4..dc4158c600 100644 --- a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Android0GradleIntegrationTest.kt +++ b/dokka-integration-tests/gradle/src/testTemplateProjectAndroid/kotlin/Android0GradleIntegrationTest.kt @@ -29,7 +29,7 @@ class Android0GradleIntegrationTest : AbstractGradleIntegrationTest() { fun assumeAndroidSdkInstalled() { if (isCI) return if (!isAndroidSdkInstalled) { - throw IllegalStateException("Expected Android SDK to be installed") + throw IllegalStateException("Expected Android SDK is installed") } } } diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleCachingIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectBasic/kotlin/AbstractGradleCachingIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/AbstractGradleCachingIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectBasic/kotlin/AbstractGradleCachingIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicCachingIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectBasic/kotlin/BasicCachingIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicCachingIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectBasic/kotlin/BasicCachingIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectBasic/kotlin/BasicGradleIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectBasic/kotlin/BasicGradleIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/GradleRelocatedCachingIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectBasic/kotlin/GradleRelocatedCachingIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/GradleRelocatedCachingIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectBasic/kotlin/GradleRelocatedCachingIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGroovyIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectBasicGroovy/kotlin/BasicGroovyIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGroovyIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectBasicGroovy/kotlin/BasicGroovyIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Collector0IntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectCollector/kotlin/Collector0IntegrationTest.kt similarity index 99% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Collector0IntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectCollector/kotlin/Collector0IntegrationTest.kt index d5eb41f669..8868b954ec 100644 --- a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Collector0IntegrationTest.kt +++ b/dokka-integration-tests/gradle/src/testTemplateProjectCollector/kotlin/Collector0IntegrationTest.kt @@ -80,4 +80,3 @@ class Collector0IntegrationTest : AbstractGradleIntegrationTest() { assertTrue(isDirectory, "Missing dokka gfmCollector output directory") } } - diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/ConfigurationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectConfiguration/kotlin/ConfigurationTest.kt similarity index 98% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/ConfigurationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectConfiguration/kotlin/ConfigurationTest.kt index c233f9398d..3e55989285 100644 --- a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/ConfigurationTest.kt +++ b/dokka-integration-tests/gradle/src/testTemplateProjectConfiguration/kotlin/ConfigurationTest.kt @@ -43,7 +43,6 @@ class ConfigurationTest : AbstractGradleIntegrationTest() { */ @ParameterizedTest(name = "{0}") @ArgumentsSource(LatestTestedVersionsArgumentsProvider::class) - @Suppress("FunctionName") fun `should fail with DokkaException and readable message if failOnWarning is triggered`( buildVersions: BuildVersions ) { diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/JsIRGradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectJsIr/kotlin/JsIRGradleIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/JsIRGradleIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectJsIr/kotlin/JsIRGradleIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/MultiModule0IntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectMultimodule0/kotlin/MultiModule0IntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/MultiModule0IntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectMultimodule0/kotlin/MultiModule0IntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/MultiModule1IntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectMultimodule1/kotlin/MultiModule1IntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/MultiModule1IntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectMultimodule1/kotlin/MultiModule1IntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/MultiModuleInterModuleLinksIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectMultimoduleInterModuleLinks/kotlin/MultiModuleInterModuleLinksIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/MultiModuleInterModuleLinksIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectMultimoduleInterModuleLinks/kotlin/MultiModuleInterModuleLinksIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Versioning0IntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectMultimoduleVersioning/kotlin/Versioning0IntegrationTest.kt similarity index 98% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Versioning0IntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectMultimoduleVersioning/kotlin/Versioning0IntegrationTest.kt index 1da782dffd..1bca769f56 100644 --- a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Versioning0IntegrationTest.kt +++ b/dokka-integration-tests/gradle/src/testTemplateProjectMultimoduleVersioning/kotlin/Versioning0IntegrationTest.kt @@ -26,7 +26,7 @@ class Versioning0IntegrationTest : AbstractGradleIntegrationTest() { /** * This test runs versioning 3 times to simulate how users might use it in the real word * - * Each version has a separate task that has a different version number from 1.0 to 1.2 and is placed under `builDir/dokkas/` + * Each version has a separate task that has a different version number from 1.0 to 1.2 and is placed under `buildDir/dokkas/` * * Output is produced in a standard build directory under `build/dokka/htmlMultiModule` */ diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Multiplatform0GradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectMultiplatform/kotlin/Multiplatform0GradleIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Multiplatform0GradleIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectMultiplatform/kotlin/Multiplatform0GradleIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/SequentialTasksExecutionStressTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectTasksExecutionStress/kotlin/SequentialTasksExecutionStressTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/SequentialTasksExecutionStressTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectTasksExecutionStress/kotlin/SequentialTasksExecutionStressTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmGradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectWasmBasic/kotlin/WasmGradleIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmGradleIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectWasmBasic/kotlin/WasmGradleIntegrationTest.kt diff --git a/dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmJsWasiGradleIntegrationTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectWasmJsWasiBasic/kotlin/WasmJsWasiGradleIntegrationTest.kt similarity index 100% rename from dokka-integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/WasmJsWasiGradleIntegrationTest.kt rename to dokka-integration-tests/gradle/src/testTemplateProjectWasmJsWasiBasic/kotlin/WasmJsWasiGradleIntegrationTest.kt diff --git a/dokka-integration-tests/utilities/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt b/dokka-integration-tests/utilities/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt index 9f409c73f3..c4d2bec6ae 100644 --- a/dokka-integration-tests/utilities/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt +++ b/dokka-integration-tests/utilities/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt @@ -18,6 +18,7 @@ abstract class AbstractIntegrationTest { @field:TempDir lateinit var tempFolder: File + /** Working directory of the test. Contains the project that should be tested. */ val projectDir: File get() = File(tempFolder, "project") fun File.allDescendentsWithExtension(extension: String): Sequence = diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index da3d779cb1..c7ef86f28c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -143,6 +143,8 @@ kotlinx-cli = { module = "org.jetbrains.kotlinx:kotlinx-cli-jvm", version.ref = #### Test dependencies #### eclipse-jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "eclipse-jgit" } +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit5", version.ref = "gradlePlugin-kotlin" } + junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" } junit-jupiterApi = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" } junit-jupiterParams = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }