-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flag to disable dumping Dokka config file
Dumping the Dokka config files is useful for debugging, but can interfere with task outputs. Here we add a flag that disables the dumping the config file by default, but we enable it for our own tests. Fix #3958
- Loading branch information
Showing
7 changed files
with
187 additions
and
5 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
143 changes: 143 additions & 0 deletions
143
dokka-runners/dokka-gradle-plugin/src/testFunctional/kotlin/DumpDokkaConfigurationTest.kt
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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
package org.jetbrains.dokka.gradle | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.core.test.TestScope | ||
import io.kotest.matchers.collections.shouldBeEmpty | ||
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder | ||
import io.kotest.matchers.file.shouldExist | ||
import org.gradle.testkit.runner.TaskOutcome.SUCCESS | ||
import org.jetbrains.dokka.gradle.internal.DokkaConstants.DOKKA_VERSION | ||
import org.jetbrains.dokka.gradle.utils.* | ||
import kotlin.io.path.invariantSeparatorsPathString | ||
import kotlin.io.path.name | ||
import kotlin.io.path.relativeToOrSelf | ||
|
||
class DumpDokkaConfigurationTest : FunSpec({ | ||
|
||
context("enabling dumpDokkaConfigurationDebugFile should dump configuration to file") { | ||
|
||
val project = initProject() | ||
|
||
project.gradleProperties { | ||
dokka { | ||
dumpDokkaConfigurationDebugFile = true | ||
} | ||
} | ||
|
||
project.runner | ||
.addArguments( | ||
":dokkaGenerateModuleHtml", | ||
":dokkaGeneratePublicationHtml", | ||
"--rerun-tasks", | ||
) | ||
.forwardOutput() | ||
.build { | ||
test("expect dokka tasks run successfully") { | ||
shouldHaveTasksWithOutcome( | ||
":dokkaGenerateModuleHtml" to SUCCESS, | ||
":dokkaGeneratePublicationHtml" to SUCCESS, | ||
) | ||
} | ||
|
||
test("expect dokka tasks generate config files") { | ||
project.dir("build/tmp") | ||
.findFiles { it.name == "dokka-configuration.json" } | ||
.map { it.relativeToOrSelf(project.projectDir).invariantSeparatorsPathString } | ||
.toList() | ||
.shouldContainExactlyInAnyOrder( | ||
"build/tmp/dokkaGeneratePublicationHtml/dokka-configuration.json", | ||
"build/tmp/dokkaGenerateModuleHtml/dokka-configuration.json" | ||
) | ||
} | ||
} | ||
} | ||
|
||
context("implicit task outputs should not contain Dokka config file") { | ||
listOf( | ||
"dumpDokkaConfigurationDebugFile is not set" to null, | ||
"dumpDokkaConfigurationDebugFile is disabled" to false, | ||
).forEach { (testName, value) -> | ||
context("when $testName ") { | ||
val project = initProject() | ||
|
||
project.gradleProperties { | ||
dokka { | ||
dumpDokkaConfigurationDebugFile = value | ||
} | ||
} | ||
|
||
project.runner | ||
.forwardOutput() | ||
.addArguments( | ||
":syncDokkaOutput", | ||
"--rerun", | ||
) | ||
.build { | ||
test("expect syncDokkaOutput runs successfully") { | ||
shouldHaveTasksWithOutcome( | ||
":syncDokkaOutput" to SUCCESS, | ||
) | ||
} | ||
|
||
test("verify sync task collects Dokka output files") { | ||
// Just a simple check to make sure that some files were copied, because testing the config | ||
// files don't exist could mean that nothing was copied and something else broke. | ||
project.file("build/tmp/syncDokkaOutput/module/module-descriptor.json") | ||
.toFile() | ||
.shouldExist() | ||
project.file("build/tmp/syncDokkaOutput/publication/index.html") | ||
.toFile() | ||
.shouldExist() | ||
} | ||
|
||
test("expect no Dokka config file in output") { | ||
project | ||
.dir("build/tmp/syncDokkaOutput") | ||
.findFiles { it.name == "dokka-configuration.json" } | ||
.map { it.relativeToOrSelf(project.projectDir).invariantSeparatorsPathString } | ||
.toList() | ||
.shouldBeEmpty() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
private fun TestScope.initProject( | ||
config: GradleProjectTest.() -> Unit = {}, | ||
): GradleProjectTest { | ||
val baseDirName = testCase.descriptor.ids() | ||
.joinToString("/") { it.value.substringAfter("org.jetbrains.dokka.gradle.").replaceNonAlphaNumeric() } | ||
|
||
return gradleKtsProjectTest( | ||
projectLocation = baseDirName, | ||
rootProjectName = "DumpDokkaConfigurationTest", | ||
) { | ||
buildGradleKts = """ | ||
|plugins { | ||
| kotlin("jvm") version embeddedKotlinVersion | ||
| id("org.jetbrains.dokka") version "$DOKKA_VERSION" | ||
|} | ||
| | ||
|val syncDokkaOutput by tasks.registering(Sync::class) { | ||
| // fetch the implicit output files of the DokkaGenerate tasks | ||
| from(tasks.dokkaGeneratePublicationHtml) { | ||
| into("publication") | ||
| } | ||
| from(tasks.dokkaGenerateModuleHtml) { | ||
| into("module") | ||
| } | ||
| into(temporaryDir) | ||
|} | ||
| | ||
""".trimMargin() | ||
|
||
createKotlinFile("src/main/kotlin/Foo.kt", "class Foo") | ||
|
||
config() | ||
} | ||
} |