diff options
author | aSemy <897017+aSemy@users.noreply.github.com> | 2023-02-23 13:42:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-23 13:42:15 +0100 |
commit | 8d23340d1c377b8f490cdee3c2c874453d321dd8 (patch) | |
tree | e579144a3630f2208df5604f0912d2cb553066f8 /runners/gradle-plugin/src/test/kotlin/org | |
parent | 8c0344e682fc4ba0e44fc740269c7ba308c47c35 (diff) | |
download | dokka-8d23340d1c377b8f490cdee3c2c874453d321dd8.tar.gz dokka-8d23340d1c377b8f490cdee3c2c874453d321dd8.tar.bz2 dokka-8d23340d1c377b8f490cdee3c2c874453d321dd8.zip |
Update custom Gradle utils to use Gradle Kotlin DSL (#2833)
Diffstat (limited to 'runners/gradle-plugin/src/test/kotlin/org')
7 files changed, 60 insertions, 36 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 index 455a906b..116104e8 100644 --- 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 @@ -49,12 +49,12 @@ class AndroidAutoConfigurationTest { dokkaTasks.flatMap { it.dokkaSourceSets }.forEach { sourceSet -> if ("test" in sourceSet.name.toLowerCase()) { assertTrue( - sourceSet.suppress.getSafe(), + sourceSet.suppress.get(), "Expected source set `${sourceSet.name}` to be suppressed by default" ) } else { assertFalse( - sourceSet.suppress.getSafe(), + sourceSet.suppress.get(), "Expected source set `${sourceSet.name}`to not be suppressed by default" ) } @@ -78,4 +78,4 @@ class AndroidAutoConfigurationTest { assertFailsWith<ResolveException> { sourceSet.classpath.files } } } -}
\ No newline at end of file +} 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 index d22dac90..b9c20dce 100644 --- 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 @@ -4,16 +4,9 @@ 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.DokkaDefaults.cacheRoot -import org.jetbrains.dokka.DokkaDefaults.failOnWarning -import org.jetbrains.dokka.DokkaDefaults.moduleName -import org.jetbrains.dokka.DokkaDefaults.offlineMode import org.jetbrains.dokka.DokkaException import java.io.File -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith -import kotlin.test.assertTrue +import kotlin.test.* class DokkaCollectorTaskTest { @@ -46,7 +39,7 @@ class DokkaCollectorTaskTest { assertTrue(collectorTasks.isNotEmpty(), "Expected at least one collector task") - collectorTasks.toList().forEach { task -> + collectorTasks.forEach { task -> val dokkaConfiguration = task.buildDokkaConfiguration() assertEquals( DokkaConfigurationImpl( @@ -63,12 +56,43 @@ class DokkaCollectorTaskTest { .map { it.plugins.resolve().toList() } .reduce { acc, mutableSet -> acc + mutableSet } ), - dokkaConfiguration + dokkaConfiguration, ) } } @Test + fun `verify that cacheRoot is optional, and not required to build DokkaConfiguration`() { + val rootProject = ProjectBuilder.builder().build() + val childProject = ProjectBuilder.builder().withParent(rootProject).build() + childProject.plugins.apply("org.jetbrains.kotlin.jvm") + + rootProject.allprojects { + plugins.apply("org.jetbrains.dokka") + tasks.withType<AbstractDokkaTask>().configureEach { + plugins.withDependencies { clear() } + } + tasks.withType<DokkaTask>().configureEach { + dokkaSourceSets.configureEach { + classpath.setFrom(emptyList<Any>()) + } + } + } + + val collectorTasks = rootProject.tasks.withType<DokkaCollectorTask>() + collectorTasks.configureEach { + cacheRoot.set(null as File?) + } + + assertTrue(collectorTasks.isNotEmpty(), "Expected at least one collector task") + + collectorTasks.forEach { task -> + val dokkaConfiguration = task.buildDokkaConfiguration() + assertNull(dokkaConfiguration.cacheRoot, "Expect that cacheRoot is null") + } + } + + @Test fun `with no child tasks throws DokkaException`() { val project = ProjectBuilder.builder().build() val collectorTask = project.tasks.create<DokkaCollectorTask>("collector") diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt index 54a34e91..d00664b5 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt @@ -38,7 +38,7 @@ class DokkaMultiModuleFileLayoutTest { val targetOutputDirectory = CompactInParent.targetChildOutputDirectory(parentTask, childTask) assertEquals( - parentTask.outputDirectory.getSafe().resolve("intermediate/child"), targetOutputDirectory, + parentTask.outputDirectory.get().resolve("intermediate/child"), targetOutputDirectory, "Expected nested file structure representing project structure" ) } @@ -50,7 +50,7 @@ class DokkaMultiModuleFileLayoutTest { val childTask = project.tasks.create<DokkaTask>("child") val parentTask = project.tasks.create<DokkaMultiModuleTask>("parent") - val sourceOutputDirectory = childTask.outputDirectory.getSafe() + val sourceOutputDirectory = childTask.outputDirectory.get() sourceOutputDirectory.mkdirs() sourceOutputDirectory.resolve("some.file").writeText("some text") val subFolder = sourceOutputDirectory.resolve("subFolder") @@ -102,7 +102,7 @@ class DokkaMultiModuleFileLayoutTest { val childTask = project.tasks.create<DokkaTask>("child") val parentTask = project.tasks.create<DokkaMultiModuleTask>("parent") parentTask.fileLayout.set(DokkaMultiModuleFileLayout { _, child -> - child.outputDirectory.getSafe().resolve("subfolder") + child.outputDirectory.get().resolve("subfolder") }) assertFailsWith<DokkaException> { parentTask.copyChildOutputDirectory(childTask) } } diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt index fb834ff8..b202fa3d 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt @@ -52,7 +52,7 @@ class GradleDokkaSourceSetBuilderTest { fun displayName() { val sourceSet = GradleDokkaSourceSetBuilder("myName", project) assertNull( - sourceSet.displayName.getSafe(), + sourceSet.displayName.orNull, "Expected no ${GradleDokkaSourceSetBuilder::displayName.name} being set by default" ) @@ -361,7 +361,7 @@ class GradleDokkaSourceSetBuilderTest { @Test fun noStdlibLink() { val sourceSet = GradleDokkaSourceSetBuilder("", project) - assertFalse(sourceSet.noStdlibLink.getSafe(), "Expected 'noStdlibLink' to be set to false by default") + assertFalse(sourceSet.noStdlibLink.get(), "Expected 'noStdlibLink' to be set to false by default") assertEquals(1, sourceSet.build().externalDocumentationLinks.count { "https://kotlinlang.org/api" in it.url.toURI().toString() @@ -379,7 +379,7 @@ class GradleDokkaSourceSetBuilderTest { @Test fun noJdkLink() { val sourceSet = GradleDokkaSourceSetBuilder("", project) - assertFalse(sourceSet.noJdkLink.getSafe(), "Expected 'noJdkLink' to be set to false by default") + assertFalse(sourceSet.noJdkLink.get(), "Expected 'noJdkLink' to be set to false by default") assertEquals(1, sourceSet.build().externalDocumentationLinks.count { "https://docs.oracle.com/" in it.url.toURI().toString() @@ -398,7 +398,7 @@ class GradleDokkaSourceSetBuilderTest { @Test fun noAndroidSdkLink() { val sourceSet = GradleDokkaSourceSetBuilder("", project) - assertFalse(sourceSet.noAndroidSdkLink.getSafe(), "Expected 'noAndroidSdkLink' to be set to false by default") + assertFalse(sourceSet.noAndroidSdkLink.get(), "Expected 'noAndroidSdkLink' to be set to false by default") assertEquals(0, sourceSet.build().externalDocumentationLinks.count { "https://developer.android.com/reference" in it.url.toURI().toString() 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 e5b8d091..52485cdc 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 @@ -18,7 +18,7 @@ class KotlinDslDokkaTaskConfigurationTest { } project.tasks.withType(DokkaTask::class.java).forEach { dokkaTask -> - assertEquals(File("test"), dokkaTask.outputDirectory.getSafe()) + assertEquals(File("test"), dokkaTask.outputDirectory.get()) } } diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt index dcb537dd..c40b5811 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt @@ -30,12 +30,12 @@ class KotlinSourceSetGistTest { ) assertEquals( - KotlinPlatformType.jvm, mainSourceSetGist.platform.getSafe(), + KotlinPlatformType.jvm, mainSourceSetGist.platform.get(), "Expected correct platform" ) assertTrue( - mainSourceSetGist.isMain.getSafe(), + mainSourceSetGist.isMain.get(), "Expected main sources to be marked as 'isMain'" ) @@ -55,7 +55,7 @@ class KotlinSourceSetGistTest { val testSourceSetGist = project.gistOf(testSourceSet) assertFalse( - testSourceSetGist.isMain.getSafe(), + testSourceSetGist.isMain.get(), "Expected test source set not being marked as 'isMain'" ) @@ -138,7 +138,7 @@ class KotlinSourceSetGistTest { } assertEquals( - emptySet(), mainSourceSetGist.classpath.getSafe().files, + emptySet(), mainSourceSetGist.classpath.get().files, "Expected no files on the classpath, since no file exists" ) @@ -149,7 +149,7 @@ class KotlinSourceSetGistTest { check(runtimeOnlyJar.createNewFile()) assertEquals( - setOf(implementationJar, compileOnlyJar, apiJar), mainSourceSetGist.classpath.getSafe().files, + setOf(implementationJar, compileOnlyJar, apiJar), mainSourceSetGist.classpath.get().files, "Expected implementation, compileOnly and api dependencies on classpath" ) } @@ -187,47 +187,47 @@ class KotlinSourceSetGistTest { ) assertEquals( - KotlinPlatformType.common, commonMainSourceSetGist.platform.getSafe(), + KotlinPlatformType.common, commonMainSourceSetGist.platform.get(), "Expected common platform for commonMain source set" ) assertEquals( - KotlinPlatformType.jvm, jvmMainSourceSetGist.platform.getSafe(), + KotlinPlatformType.jvm, jvmMainSourceSetGist.platform.get(), "Expected jvm platform for jvmMain source set" ) assertEquals( - KotlinPlatformType.native, macosMainSourceSetGist.platform.getSafe(), + KotlinPlatformType.native, macosMainSourceSetGist.platform.get(), "Expected native platform for macosMain source set" ) assertTrue( - commonMainSourceSetGist.isMain.getSafe(), + commonMainSourceSetGist.isMain.get(), "Expected commonMain to be marked with 'isMain'" ) assertTrue( - jvmMainSourceSetGist.isMain.getSafe(), + jvmMainSourceSetGist.isMain.get(), "Expected jvmMain to be marked with 'isMain'" ) assertTrue( - macosMainSourceSetGist.isMain.getSafe(), + macosMainSourceSetGist.isMain.get(), "Expected macosMain to be marked with 'isMain'" ) assertFalse( - project.gistOf(kotlin.sourceSets["commonTest"]).isMain.getSafe(), + project.gistOf(kotlin.sourceSets["commonTest"]).isMain.get(), "Expected commonTest not being marked with 'isMain'" ) assertFalse( - project.gistOf(kotlin.sourceSets["jvmTest"]).isMain.getSafe(), + project.gistOf(kotlin.sourceSets["jvmTest"]).isMain.get(), "Expected jvmTest not being marked with 'isMain'" ) assertFalse( - project.gistOf(kotlin.sourceSets["macosTest"]).isMain.getSafe(), + project.gistOf(kotlin.sourceSets["macosTest"]).isMain.get(), "Expected macosTest not being marked with 'isMain'" ) diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTaskTest.kt index 015d25f9..ecbe3355 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTaskTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTaskTest.kt @@ -101,7 +101,7 @@ class DokkaMultiModuleTaskTest { name = "child", relativePathToOutputDirectory = File("child"), includes = setOf(include1, include2), - sourceOutputDirectory = childDokkaTask.outputDirectory.getSafe() + sourceOutputDirectory = childDokkaTask.outputDirectory.get() ) ) ), |