Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example to demonstrate how to configure a custom Dokka plugin #3871

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ abstract class SystemPropertyAdder @Inject internal constructor(
return task.inputs.property("SystemProperty input property $key", value)
}

fun inputProperty(
key: String,
value: String,
): TaskInputPropertyBuilder {
task.jvmArgumentProviders.add(
SystemPropertyArgumentProvider(key, value) { it }
)
return task.inputs.property("SystemProperty input property $key", value)
}

@JvmName("inputBooleanProperty")
fun inputProperty(
key: String,
Expand Down
7 changes: 7 additions & 0 deletions build-logic/src/main/kotlin/dokkabuild/utils/strings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package dokkabuild.utils

/** Title case the first char of a string */
fun String.uppercaseFirstChar(): String = replaceFirstChar(Char::uppercaseChar)
31 changes: 29 additions & 2 deletions dokka-integration-tests/gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

import dokkabuild.tasks.GitCheckoutTask
import dokkabuild.utils.systemProperty
import dokkabuild.utils.uppercaseFirstChar
import org.gradle.api.tasks.PathSensitivity.NAME_ONLY
import org.gradle.api.tasks.PathSensitivity.RELATIVE
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.name

plugins {
id("dokkabuild.kotlin-jvm")
Expand Down Expand Up @@ -197,10 +200,11 @@ testing {
}
}
val testExampleProjects by suites.registering(JvmTestSuite::class) {
val exampleGradleProjectsDir = projectDir.resolve("../../examples/gradle-v2")

targets.configureEach {
testTask.configure {
testTask {

val exampleGradleProjectsDir = projectDir.resolve("../../examples/gradle-v2")
systemProperty
.inputDirectory("exampleGradleProjectsDir", exampleGradleProjectsDir)
.withPathSensitivity(RELATIVE)
Expand All @@ -215,5 +219,28 @@ testing {
systemProperty("junit.jupiter.execution.parallel.mode.default", "CONCURRENT")
}
}

// Register specific Gradle test runs for each example so the examples can be tested individually.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we discussed this in the previous PR, but I still feel that it would be more conventional to have a generated testGen source directory (under git and with an idempotency check) than a per test project Gradle task

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the benefits is that you could then run an arbitrary subset of such tests using the standard Test task's --tests filter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, those would be good benefits. I'm just struggling to think about how to generate tests dynamically though, because I usually find code generation inconvenient and prone to mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you decide to look further into the direction of generating test cases, I think the setup is usually something like:

  • src/MyTestsInfrastructure.kt
abstract class TestsInfrastructure  {
  // hand craft some eloquent testing infrastructure with an API that easy to generate in 1 LOC
  fun runTest(testDataPath: String) { ... }
}
  • src/tests-gen/Tests.kt
// This class is generated
class Tests : TestsInfrastructure {
  @Test
  fun test_basicExample() = runTest("path/to/basicExample")
}

exampleGradleProjectsDir.toPath()
.listDirectoryEntries()
.map { it.name }
.filter {
it.endsWith("-example")
// note: avoid checks like `isDirectory()` to prevent Gradle registering the files as CC inputs.
abdulowork marked this conversation as resolved.
Show resolved Hide resolved
}
.forEach { exampleProjectName ->
val prettyName = exampleProjectName
.removeSuffix("-example")
.split("-")
.joinToString("") { it.uppercaseFirstChar() }

targets.register("testExample$prettyName") {
testTask {
description = "Only test $exampleProjectName"
group = "verification - example projects"
systemProperty.inputProperty("exampleProjectFilter", exampleProjectName)
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading