aboutsummaryrefslogtreecommitdiff
path: root/runners/gradle-plugin/src/test/kotlin
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-07-18 12:18:59 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-14 17:51:11 +0200
commiteae1ce49d18c2978b49166ea502bf2c109a85504 (patch)
tree477f39e33f14c71042f06eecc938d6efaa95e66c /runners/gradle-plugin/src/test/kotlin
parent6c635551ed3ea0cfe5f04b54a98cb28225061d26 (diff)
downloaddokka-eae1ce49d18c2978b49166ea502bf2c109a85504.tar.gz
dokka-eae1ce49d18c2978b49166ea502bf2c109a85504.tar.bz2
dokka-eae1ce49d18c2978b49166ea502bf2c109a85504.zip
Simplify Dokka Gradle Plugin
Diffstat (limited to 'runners/gradle-plugin/src/test/kotlin')
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt107
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTaskTest.kt60
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt51
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt13
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt112
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt5
6 files changed, 292 insertions, 56 deletions
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt
new file mode 100644
index 00000000..da0f3f35
--- /dev/null
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt
@@ -0,0 +1,107 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.kotlin.dsl.register
+import org.gradle.kotlin.dsl.withType
+import org.gradle.testfixtures.ProjectBuilder
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+class AbstractDokkaParentTaskTest {
+
+ private val rootProject = ProjectBuilder.builder().build()
+ private val subproject0 = ProjectBuilder.builder().withName("subproject0").withParent(rootProject).build()
+ private val subproject1 = ProjectBuilder.builder().withName("subproject1").withParent(rootProject).build()
+ private val subSubproject0a = ProjectBuilder.builder().withName("subSubproject0a").withParent(subproject0).build()
+
+ init {
+ rootProject.allprojects { project -> project.plugins.apply("org.jetbrains.dokka") }
+ }
+
+ private val parentTasks = rootProject.tasks.withType<AbstractDokkaParentTask>().toList()
+
+ @Test
+ fun `at least one parent task is registered`() {
+ assertTrue(
+ parentTasks.isNotEmpty(),
+ "Expected at least one ${AbstractDokkaParentTask::class.simpleName} task in rootProject"
+ )
+ }
+
+ @Test
+ fun `configuring subprojects`() {
+ parentTasks.forEach { task ->
+ assertEquals(
+ setOf(":subproject0", ":subproject1", ":subproject0:subSubproject0a"), task.subprojectPaths,
+ "Expected all sub projects registered by default"
+ )
+
+ assertEquals(
+ listOf(subproject0, subproject1, subSubproject0a), task.subprojects,
+ "Expected all sub projects registered by default"
+ )
+
+ assertEquals(3, task.dokkaTasks.size, "Expected three referenced dokka tasks")
+ assertTrue(listOf(subproject0, subproject1, subSubproject0a).all { project ->
+ task.dokkaTasks.any { task -> task in project.tasks }
+ }, "Expected all sub projects to contribute to referenced dokka tasks")
+
+ task.removeSubproject(subproject0)
+ assertEquals(
+ setOf(":subproject1", ":subproject0:subSubproject0a"), task.subprojectPaths,
+ "Expected subproject0 to be removed (without removing its children)"
+ )
+
+ task.addSubproject(subproject0)
+ assertEquals(
+ setOf(":subproject1", ":subproject0:subSubproject0a", ":subproject0"), task.subprojectPaths,
+ "Expected subproject0 being added again"
+ )
+
+ task.addSubproject(subproject0)
+ assertEquals(
+ setOf(":subproject1", ":subproject0:subSubproject0a", ":subproject0"), task.subprojectPaths,
+ "Expected adding same project twice to be ignored"
+ )
+
+ task.removeAllProjects(subproject0)
+ assertEquals(
+ setOf(":subproject1"), task.subprojectPaths,
+ "Expected subproject0 and subSubproject0a to be removed"
+ )
+
+ task.addAllProjects(subproject0)
+ assertEquals(
+ setOf(":subproject1", ":subproject0", ":subproject0:subSubproject0a"), task.subprojectPaths,
+ "Expected subproject0 and subSubproject0a to be added again"
+ )
+ }
+ }
+
+ @Test
+ fun `configure dokkaTaskNames`() {
+ parentTasks.forEach { task ->
+ assertEquals(
+ 3, task.dokkaTasks.size,
+ "Expected 3 tasks referenced by default"
+ )
+
+ val customDokkaTaskName = "custom${task.name}"
+ task.dokkaTaskNames = setOf(customDokkaTaskName)
+ assertTrue(task.dokkaTasks.isEmpty(), "Expected no $customDokkaTaskName. Found: ${task.dokkaTasks}")
+
+ rootProject.subprojects { subproject ->
+ subproject.tasks.register<DokkaTask>(customDokkaTaskName)
+ }
+
+ assertEquals(
+ 3, task.dokkaTasks.size,
+ "Expected three $customDokkaTaskName found"
+ )
+
+ task.dokkaTasks.forEach { dokkaTask ->
+ assertEquals(customDokkaTaskName, dokkaTask.name)
+ }
+ }
+ }
+}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTaskTest.kt
new file mode 100644
index 00000000..2d8dc21a
--- /dev/null
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTaskTest.kt
@@ -0,0 +1,60 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.api.artifacts.Dependency
+import org.gradle.api.artifacts.FileCollectionDependency
+import org.gradle.kotlin.dsl.withType
+import org.gradle.testfixtures.ProjectBuilder
+import org.jetbrains.dokka.DokkaConfigurationImpl
+import java.io.File
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+class DokkaCollectorTaskTest {
+
+ @Test
+ fun buildDokkaConfiguration() {
+ val rootProject = ProjectBuilder.builder().build()
+ val childProject = ProjectBuilder.builder().withParent(rootProject).build()
+ childProject.plugins.apply("org.jetbrains.kotlin.jvm")
+
+ rootProject.allprojects { project ->
+ project.plugins.apply("org.jetbrains.dokka")
+ project.tasks.withType<AbstractDokkaTask>().configureEach { task ->
+ task.plugins.withDependencies { dependencies -> dependencies.clear() }
+ }
+ }
+
+ val collectorTasks = rootProject.tasks.withType<DokkaCollectorTask>()
+ collectorTasks.configureEach { task ->
+ task.outputDirectory = File("customOutputDirectory")
+ task.cacheRoot = File("customCacheRoot")
+ task.failOnWarning = true
+ task.offlineMode = true
+ }
+
+ assertTrue(collectorTasks.isNotEmpty(), "Expected at least one collector task")
+
+ collectorTasks.forEach { task ->
+ val dokkaConfiguration = task.buildDokkaConfiguration()
+ assertEquals(
+ DokkaConfigurationImpl(
+ outputDir = File("customOutputDirectory"),
+ cacheRoot = File("customCacheRoot"),
+ failOnWarning = true,
+ offlineMode = true,
+ sourceSets = task.dokkaTasks
+ .map { it.buildDokkaConfiguration() }
+ .map { it.sourceSets }
+ .reduce { acc, list -> acc + list },
+ pluginsClasspath = task.dokkaTasks
+ .map { it.plugins.resolve() }
+ .reduce { acc, mutableSet -> acc + mutableSet }
+ .toList()
+ ),
+ dokkaConfiguration
+ )
+ }
+
+ }
+}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt
index d80f43e4..f6a9c909 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt
@@ -3,6 +3,7 @@ package org.jetbrains.dokka.gradle
import org.gradle.kotlin.dsl.withType
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.dokka.*
+import java.io.File
import java.net.URL
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -20,8 +21,8 @@ class DokkaConfigurationJsonTest {
dokkaTask.apply {
this.failOnWarning = true
this.offlineMode = true
- this.outputDirectory = "customOutputDir"
- this.cacheRoot = "customCacheRoot"
+ this.outputDirectory = File("customOutputDir")
+ this.cacheRoot = File("customCacheRoot")
this.pluginsConfiguration["0"] = "a"
this.pluginsConfiguration["1"] = "b"
this.dokkaSourceSets.create("main") { sourceSet ->
@@ -33,12 +34,6 @@ class DokkaConfigurationJsonTest {
link.packageListUrl = URL("http://some.url")
link.url = URL("http://some.other.url")
}
- sourceSet.collectKotlinTasks = {
- println(this@DokkaConfigurationJsonTest)
- println("This lambda is capturing the entire test")
- emptyList()
- }
-
sourceSet.perPackageOption { packageOption ->
packageOption.includeNonPublic = true
packageOption.reportUndocumented = true
@@ -47,47 +42,11 @@ class DokkaConfigurationJsonTest {
}
}
- val sourceConfiguration = dokkaTask.getConfigurationOrThrow()
+ val sourceConfiguration = dokkaTask.buildDokkaConfiguration()
val configurationJson = sourceConfiguration.toJsonString()
val parsedConfiguration = DokkaConfigurationImpl(configurationJson)
- assertEquals(
- DokkaConfigurationImpl(
- failOnWarning = sourceConfiguration.failOnWarning,
- offlineMode = sourceConfiguration.offlineMode,
- outputDir = sourceConfiguration.outputDir,
- cacheRoot = sourceConfiguration.cacheRoot,
- pluginsClasspath = emptyList(),
- pluginsConfiguration = sourceConfiguration.pluginsConfiguration.toMap(),
- sourceSets = listOf(
- DokkaSourceSetImpl(
- moduleDisplayName = sourceConfiguration.sourceSets.single().moduleDisplayName,
- displayName = sourceConfiguration.sourceSets.single().displayName,
- reportUndocumented = sourceConfiguration.sourceSets.single().reportUndocumented,
- externalDocumentationLinks = sourceConfiguration.sourceSets.single().externalDocumentationLinks
- .map { link ->
- ExternalDocumentationLinkImpl(
- url = link.url,
- packageListUrl = link.packageListUrl
- )
- },
- perPackageOptions = sourceConfiguration.sourceSets.single().perPackageOptions.map { option ->
- PackageOptionsImpl(
- prefix = option.prefix,
- includeNonPublic = option.includeNonPublic,
- reportUndocumented = option.reportUndocumented,
- skipDeprecated = option.skipDeprecated,
- suppress = option.suppress
- )
- },
- sourceSetID = sourceConfiguration.sourceSets.single().sourceSetID,
- sourceRoots = sourceConfiguration.sourceSets.single().sourceRoots.map { sourceRoot ->
- SourceRootImpl(sourceRoot.path)
- }
- )
- )
- ), parsedConfiguration
- )
+ assertEquals(sourceConfiguration, parsedConfiguration)
println(parsedConfiguration)
}
}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt
index 70ecfcf0..e4fd0676 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt
@@ -6,6 +6,7 @@ import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.toJsonString
import org.junit.Rule
import org.junit.rules.TemporaryFolder
+import java.io.File
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.net.URL
@@ -28,8 +29,8 @@ class DokkaConfigurationSerializableTest {
dokkaTask.apply {
this.failOnWarning = true
this.offlineMode = true
- this.outputDirectory = "customOutputDir"
- this.cacheRoot = "customCacheRoot"
+ this.outputDirectory = File("customOutputDir")
+ this.cacheRoot = File("customCacheRoot")
this.pluginsConfiguration["0"] = "a"
this.pluginsConfiguration["1"] = "b"
this.dokkaSourceSets.create("main") { sourceSet ->
@@ -41,9 +42,6 @@ class DokkaConfigurationSerializableTest {
link.packageListUrl = URL("http://some.url")
link.url = URL("http://some.other.url")
}
- sourceSet.collectKotlinTasks = {
- emptyList()
- }
sourceSet.perPackageOption { packageOption ->
packageOption.includeNonPublic = true
@@ -53,7 +51,7 @@ class DokkaConfigurationSerializableTest {
}
}
- val sourceConfiguration = dokkaTask.getConfigurationOrThrow()
+ val sourceConfiguration = dokkaTask.buildDokkaConfiguration()
val configurationFile = temporaryFolder.root.resolve("config.bin")
ObjectOutputStream(configurationFile.outputStream()).use { stream ->
stream.writeObject(sourceConfiguration)
@@ -62,7 +60,6 @@ class DokkaConfigurationSerializableTest {
stream.readObject() as DokkaConfiguration
}
- /* Abusing toJsonString, since there is no proper .equals on the gradle implementations yet */
- assertEquals(sourceConfiguration.toJsonString(), parsedConfiguration.toJsonString())
+ assertEquals(sourceConfiguration, parsedConfiguration)
}
}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt
new file mode 100644
index 00000000..ff318bdf
--- /dev/null
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt
@@ -0,0 +1,112 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.kotlin.dsl.create
+import org.gradle.kotlin.dsl.withType
+import org.gradle.testfixtures.ProjectBuilder
+import org.jetbrains.dokka.DokkaConfigurationImpl
+import org.jetbrains.dokka.DokkaModuleDescriptionImpl
+import java.io.File
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+class DokkaMultiModuleTaskTest {
+
+ private val rootProject = ProjectBuilder.builder()
+ .withName("root")
+ .build()
+
+ private val childProject = ProjectBuilder.builder()
+ .withName("child")
+ .withProjectDir(rootProject.projectDir.resolve("child"))
+ .withParent(rootProject).build()
+
+ init {
+ rootProject.allprojects { project ->
+ project.plugins.apply("org.jetbrains.kotlin.jvm")
+ project.plugins.apply("org.jetbrains.dokka")
+ project.tasks.withType<AbstractDokkaTask>().configureEach { task ->
+ task.plugins.withDependencies { dependencies -> dependencies.clear() }
+ }
+ }
+ }
+
+ @Test
+ fun `child project is withing root project`() {
+ assertEquals(
+ rootProject.projectDir, childProject.projectDir.parentFile,
+ "Expected child project being inside the root project"
+ )
+
+ assertEquals(
+ childProject.projectDir.name, "child",
+ "Expected folder of child project to be called 'child'"
+ )
+ }
+
+ @Test
+ fun buildDokkaConfiguration() {
+ childProject.tasks.withType<DokkaTask>().configureEach { task ->
+ task.outputDirectory = task.project.buildDir.resolve("output")
+ }
+
+ val multimoduleTasks = rootProject.tasks.withType<DokkaMultimoduleTask>()
+ assertTrue(multimoduleTasks.isNotEmpty(), "Expected at least one multimodule task")
+
+ multimoduleTasks.configureEach { task ->
+ task.documentationFileName = "customDocumentationFileName.md"
+ task.outputDirectory = task.project.buildDir.resolve("customOutputDirectory")
+ task.cacheRoot = File("customCacheRoot")
+ task.pluginsConfiguration["pluginA"] = "configA"
+ task.failOnWarning = true
+ task.offlineMode = true
+ }
+
+ multimoduleTasks.forEach { task ->
+ val dokkaConfiguration = task.buildDokkaConfiguration()
+ assertEquals(
+ DokkaConfigurationImpl(
+ outputDir = task.project.buildDir.resolve("customOutputDirectory"),
+ cacheRoot = File("customCacheRoot"),
+ pluginsConfiguration = mapOf("pluginA" to "configA"),
+ pluginsClasspath = emptyList(),
+ failOnWarning = true,
+ offlineMode = true,
+ modules = listOf(
+ DokkaModuleDescriptionImpl(
+ name = "child",
+ path = File("../../child/build/output"),
+ docFile = childProject.projectDir.resolve("customDocumentationFileName.md")
+ )
+ )
+ ),
+ dokkaConfiguration
+ )
+ }
+ }
+
+ @Test
+ fun `setting dokkaTaskNames declares proper task dependencies`() {
+ val multimoduleTasks = rootProject.tasks.withType<DokkaMultimoduleTask>()
+ assertTrue(multimoduleTasks.isNotEmpty(), "Expected at least one multimodule task")
+
+ multimoduleTasks.toList().forEach { task ->
+ val dependencies = task.taskDependencies.getDependencies(task).toSet()
+ assertEquals(1, dependencies.size, "Expected one dependency")
+ val dependency = dependencies.single()
+
+ assertTrue(dependency is DokkaTask, "Expected dependency to be of Type ${DokkaTask::class.simpleName}")
+ assertEquals(childProject, dependency.project, "Expected dependency from child project")
+ }
+
+ val customDokkaTask = childProject.tasks.create<DokkaTask>("customDokkaTask")
+
+ multimoduleTasks.toList().forEach { task ->
+ task.dokkaTaskNames += "customDokkaTask"
+ val dependencies = task.taskDependencies.getDependencies(task).toSet()
+
+ assertEquals(2, dependencies.size, "Expected two dependencies")
+ assertTrue(customDokkaTask in dependencies, "Expected 'customDokkaTask' in dependencies")
+ }
+ }
+}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt
index 7b78fb55..f4029bd5 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt
@@ -3,6 +3,7 @@ package org.jetbrains.dokka.gradle
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.dokka.DokkaSourceSetID
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
+import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -13,11 +14,11 @@ class KotlinDslDokkaTaskConfigurationTest {
val project = ProjectBuilder.builder().build()
project.plugins.apply("org.jetbrains.dokka")
project.tasks.withType(DokkaTask::class.java).forEach { dokkaTask ->
- dokkaTask.outputDirectory = "test"
+ dokkaTask.outputDirectory = File("test")
}
project.tasks.withType(DokkaTask::class.java).forEach { dokkaTask ->
- assertEquals("test", dokkaTask.outputDirectory)
+ assertEquals(File("test"), dokkaTask.outputDirectory)
}
}