Skip to content

Commit

Permalink
Add test for DokkaSourceSetSpec conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-enko committed Nov 25, 2024
1 parent f0bbb1b commit b8b5f8b
Showing 1 changed file with 133 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* 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.engine.parameters

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldBeEmpty
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
import io.kotest.matchers.shouldBe
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.getByType
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.dokka.gradle.DokkaExtension
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier.Public
import org.jetbrains.dokka.gradle.utils.create_
import org.jetbrains.dokka.gradle.utils.enableV2Plugin

class DokkaSourceSetSpecTest : FunSpec({

context("verify DokkaSourceSetSpec conventions") {
val project = createProject()
val dss = project.createDokkaSourceSetSpec("foo")

test("analysisPlatform") {
dss.analysisPlatform.orNull shouldBe KotlinPlatform.DEFAULT
}
test("apiVersion") {
dss.apiVersion.orNull shouldBe null
}
test("classpath") {
dss.classpath.shouldBeEmpty()
}
test("dependentSourceSets") {
dss.dependentSourceSets.shouldBeEmpty()
}
test("displayName") {
dss.displayName.orNull shouldBe "jvm"
}
test("documentedVisibilities") {
dss.documentedVisibilities.orNull shouldBe setOf(Public)
}
test("enableAndroidDocumentationLink") {
dss.enableAndroidDocumentationLink.orNull shouldBe false
}
test("enableJdkDocumentationLink") {
dss.enableJdkDocumentationLink.orNull shouldBe true
}
test("enableKotlinStdLibDocumentationLink") {
dss.enableKotlinStdLibDocumentationLink.orNull shouldBe true
}
test("externalDocumentationLinks") {
dss.externalDocumentationLinks
.map { it.run { "$name enabled:${enabled.orNull} url:${url.orNull} packageList:${packageListUrl.orNull}" } }
.shouldContainExactlyInAnyOrder(
"androidSdk enabled:false url:https://developer.android.com/reference/kotlin/ packageList:https://developer.android.com/reference/kotlin/package-list",
"androidX enabled:false url:https://developer.android.com/reference/kotlin/ packageList:https://developer.android.com/reference/kotlin/androidx/package-list",
"jdk enabled:true url:https://docs.oracle.com/en/java/javase/11/docs/api/ packageList:https://docs.oracle.com/en/java/javase/11/docs/api/element-list",
"kotlinStdlib enabled:true url:https://kotlinlang.org/api/latest/jvm/stdlib/ packageList:https://kotlinlang.org/api/latest/jvm/stdlib/package-list",
)
}
test("includes") {
dss.includes.shouldBeEmpty()
}
test("jdkVersion") {
dss.jdkVersion.orNull shouldBe 11
}
test("languageVersion") {
dss.languageVersion.orNull shouldBe null
}
test("name") {
dss.name shouldBe "foo"
}
test("perPackageOptions") {
dss.perPackageOptions.shouldBeEmpty()
}
test("reportUndocumented") {
dss.reportUndocumented.orNull shouldBe false
}
test("samples") {
dss.samples.shouldBeEmpty()
}
test("skipDeprecated") {
dss.skipDeprecated.orNull shouldBe false
}
test("skipEmptyPackages") {
dss.skipEmptyPackages.orNull shouldBe true
}
test("sourceLinks") {
dss.sourceLinks.shouldBeEmpty()
}
test("sourceRoots") {
dss.sourceRoots.shouldBeEmpty()
}
test("sourceSetId") {
dss.sourceSetId.orNull?.toString() shouldBe "DokkaSourceSetIdSpec(:/foo)"
}
test("sourceSetScope") {
dss.sourceSetScope.orNull shouldBe ":"
dss.sourceSetScope.orNull shouldBe project.path
}
test("suppress") {
dss.suppress.orNull shouldBe false
}
test("suppressGeneratedFiles") {
dss.suppressGeneratedFiles.orNull shouldBe true
}
test("suppressedFiles") {
dss.suppressedFiles.shouldBeEmpty()
}
}
}) {
companion object {
private fun createProject(): Project {
val project = ProjectBuilder.builder().build()
project.enableV2Plugin()
project.plugins.apply(type = DokkaPlugin::class)
return project
}

private fun Project.createDokkaSourceSetSpec(
name: String,
configure: DokkaSourceSetSpec.() -> Unit = {}
): DokkaSourceSetSpec {
return extensions
.getByType<DokkaExtension>()
.dokkaSourceSets
.create_(name, configure)
}

}
}

0 comments on commit b8b5f8b

Please sign in to comment.