diff options
Diffstat (limited to 'runners/gradle-plugin/src/test/kotlin/org/jetbrains')
5 files changed, 231 insertions, 1 deletions
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AndroidAutoConfigurationTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AndroidAutoConfigurationTest.kt new file mode 100644 index 00000000..76215762 --- /dev/null +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AndroidAutoConfigurationTest.kt @@ -0,0 +1,79 @@ +package org.jetbrains.dokka.gradle + +import com.android.build.gradle.LibraryExtension +import org.gradle.api.artifacts.ResolveException +import org.gradle.api.internal.project.ProjectInternal +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.withType +import org.gradle.testfixtures.ProjectBuilder +import kotlin.test.* + +class AndroidAutoConfigurationTest { + + private val project = ProjectBuilder.builder().build().also { project -> + project.plugins.apply("com.android.library") + project.plugins.apply("org.jetbrains.kotlin.android") + project.plugins.apply("org.jetbrains.dokka") + project.extensions.configure<LibraryExtension> { + compileSdkVersion(28) + } + } + + @Test + fun `at least one dokka task created`() { + val dokkaTasks = project.tasks.withType<DokkaTask>().toList() + assertTrue(dokkaTasks.isNotEmpty(), "Expected at least one dokka task") + } + + @Test + fun `all default source sets are present in dokka`() { + val dokkaTasks = project.tasks.withType<DokkaTask>().toList() + dokkaTasks.forEach { task -> + val sourceSets = task.dokkaSourceSets.toList() + assertEquals( + listOf( + "androidTest", "androidTestDebug", "debug", "main", + "release", "test", "testDebug", "testRelease" + ).sorted(), + sourceSets.map { it.name }.sorted(), + "Expected all default source sets being registered" + ) + } + } + + @Test + fun `test source sets are suppressed`() { + val dokkaTasks = project.tasks.withType<DokkaTask>().toList() + project as ProjectInternal + project.evaluate() + dokkaTasks.flatMap { it.dokkaSourceSets }.forEach { sourceSet -> + if ("test" in sourceSet.name.toLowerCase()) { + assertTrue( + sourceSet.suppress.getSafe(), + "Expected source set `${sourceSet.name}` to be suppressed by default" + ) + } else { + assertFalse( + sourceSet.suppress.getSafe(), + "Expected source set `${sourceSet.name}`to not be suppressed by default" + ) + } + } + } + + @Test + fun `source sets have non-empty classpath`() { + val dokkaTasks = project.tasks.withType<DokkaTask>().toList() + project as ProjectInternal + project.evaluate() + + dokkaTasks.flatMap { it.dokkaSourceSets }.forEach { sourceSet -> + /* + There is no better way of checking for empty classpath at the moment (without resolving dependencies). + We assume, that an empty classpath can be resolved + We assume, that a non-empty classpath will not be able to resolve (no repositories defined) + */ + assertFailsWith<ResolveException> { sourceSet.classpath.files } + } + } +} diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/CheckSourceSetDependenciesTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/CheckSourceSetDependenciesTest.kt new file mode 100644 index 00000000..cc0efea4 --- /dev/null +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/CheckSourceSetDependenciesTest.kt @@ -0,0 +1,67 @@ +package org.jetbrains.dokka.gradle + +import org.gradle.testfixtures.ProjectBuilder +import java.lang.IllegalArgumentException +import kotlin.test.Test +import kotlin.test.assertFailsWith +import kotlin.test.assertTrue + +class CheckSourceSetDependenciesTest { + + private val project = ProjectBuilder.builder().build() + + @Test + fun `passes when properly configured`() { + val sourceSets = listOf( + GradleDokkaSourceSetBuilder("common", project), + GradleDokkaSourceSetBuilder("jvmAndJsCommon", project).apply { + dependsOn("common") + }, + GradleDokkaSourceSetBuilder("jvm", project).apply { + dependsOn("jvmAndJsCommon") + }, + GradleDokkaSourceSetBuilder("js", project).apply { + dependsOn("jvmAndJsCommon") + } + ) + checkSourceSetDependencies(sourceSets) + } + + @Test + fun `throws exception when dependent source set id cant be found`() { + val sourceSets = listOf( + GradleDokkaSourceSetBuilder("main", project), + GradleDokkaSourceSetBuilder("bad", project).apply { + dependsOn("missing") + } + ) + + val exception = assertFailsWith<IllegalArgumentException> { + checkSourceSetDependencies(sourceSets) + } + + assertTrue("bad" in exception.message.orEmpty(), "Expected name of source set mentioned") + assertTrue("missing" in exception.message.orEmpty(), "Expected name of missing source set mentioned") + } + + @Test + fun `throws exception when documented source set depends on suppressed source set`() { + val sourceSets = listOf( + GradleDokkaSourceSetBuilder("common", project), + GradleDokkaSourceSetBuilder("intermediate", project).apply { + dependsOn("common") + suppress by true + }, + GradleDokkaSourceSetBuilder("jvm", project).apply { + dependsOn("intermediate") + } + ) + + val exception = assertFailsWith<IllegalArgumentException> { + checkSourceSetDependencies(sourceSets) + } + + assertTrue("intermediate" in exception.message.orEmpty()) + assertTrue("jvm" in exception.message.orEmpty()) + } +} diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt index c4525f72..efe03c56 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt @@ -1,7 +1,9 @@ package org.jetbrains.dokka.gradle import org.gradle.api.artifacts.FileCollectionDependency +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.property import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.dokka.Platform import org.jetbrains.dokka.gradle.kotlin.KotlinSourceSetGist @@ -27,7 +29,6 @@ class ConfigureWithKotlinSourceSetGistTest { name = "customName", platform = project.provider { KotlinPlatformType.common }, isMain = project.provider { true }, - // TODO NOW: Test if it changes classpath = project.provider { project.files(f1Jar, f2Jar) }, sourceRoots = project.files(customSourceRoot), dependentSourceSetNames = project.provider { setOf("customRootSourceSet") } @@ -121,4 +122,45 @@ class ConfigureWithKotlinSourceSetGistTest { "Expected customRoot being added to source roots in dokkaSourceSet" ) } + + @Test + fun `changing classpath`() { + val project = ProjectBuilder.builder().build() + val dokkaSourceSet = GradleDokkaSourceSetBuilder("main", project) + var classpath = project.files() + + dokkaSourceSet.configureWithKotlinSourceSetGist( + KotlinSourceSetGist( + name = "gist", + platform = project.provider { KotlinPlatformType.common }, + isMain = project.provider { true }, + dependentSourceSetNames = project.provider { emptySet() }, + sourceRoots = project.files(), + classpath = project.provider { classpath } + ) + ) + + dokkaSourceSet.classpath.from("base.jar") + classpath.from("f1.jar") + classpath.from("f2.jar") + assertEquals( + setOf(project.file("f1.jar"), project.file("f2.jar"), project.file("base.jar")), + dokkaSourceSet.classpath.files, + "Expected files from initial gist classpath and manually added file base.jar to be present in classpath" + ) + + /* + Swapping the original file collection in favour of a new one. + We expect that the base.jar is still present, as it was configured on the dokka source set. + We also expect, that the new files from the new file collection are replacing old ones + */ + classpath = project.files("f3.jar", "f4.jar") + assertEquals( + setOf(project.file("f3.jar"), project.file("f4.jar"), project.file("base.jar")), + dokkaSourceSet.classpath.files, + "Expected files from changed gist classpath and manually added file base.jar to be present in classpath" + ) + } + + } diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt new file mode 100644 index 00000000..139ebd3a --- /dev/null +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt @@ -0,0 +1,27 @@ +package org.jetbrains.dokka.gradle + +import org.gradle.kotlin.dsl.create +import org.gradle.testfixtures.ProjectBuilder +import kotlin.test.Test +import kotlin.test.assertEquals + +class DokkaTaskTest { + @Test + fun `no suppressed source sets are present after in built configuration`() { + val project = ProjectBuilder.builder().build() + val task = project.tasks.create<DokkaTask>("dokkaTask") + project.configurations.all { configuration -> configuration.withDependencies { it.clear() } } + + task.dokkaSourceSets.register("main") + task.dokkaSourceSets.register("jvm") + task.dokkaSourceSets.register("test") { + it.suppress by true + } + + assertEquals( + listOf("main", "jvm").sorted(), + task.buildDokkaConfiguration().sourceSets.map { it.sourceSetID.sourceSetName }.sorted(), + "Expected only unsuppressed source sets `main` and `test` to be present in built configuration" + ) + } +} diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/IsMainSourceSetTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/IsMainSourceSetTest.kt new file mode 100644 index 00000000..c354c62f --- /dev/null +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/IsMainSourceSetTest.kt @@ -0,0 +1,15 @@ +package org.jetbrains.dokka.gradle + +import org.jetbrains.dokka.gradle.kotlin.isMainSourceSet +import kotlin.test.Test +import kotlin.test.assertTrue + +class IsMainSourceSetTest { + @Test + fun `missing compilations will return true`() { + assertTrue( + isMainSourceSet(emptyList()), + "Expected 'isMainSourceSet' to return 'true' when no compilations are found" + ) + } +} |