From caf48e76f3bff5e9907cd094cf0719f623e528d5 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Wed, 8 Jul 2020 10:47:05 +0200 Subject: Implement simple MavenIntegrationTest.kt --- .../dokka/it/maven/MavenIntegrationTest.kt | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt (limited to 'integration-tests/maven/src/integrationTest') diff --git a/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt b/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt new file mode 100644 index 00000000..e52debf4 --- /dev/null +++ b/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt @@ -0,0 +1,78 @@ +package org.jetbrains.dokka.it.maven + +import org.jetbrains.dokka.it.AbstractIntegrationTest +import org.jetbrains.dokka.it.awaitProcessResult +import java.io.File +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class MavenIntegrationTest : AbstractIntegrationTest() { + + val currentDokkaVersion: String = checkNotNull(System.getenv("DOKKA_VERSION")) + + val mavenBinaryFile: File = File(checkNotNull(System.getenv("MVN_BINARY_PATH"))) + + @BeforeTest + fun prepareProjectFiles() { + val templateProjectDir = File("projects", "it-maven") + templateProjectDir.copyRecursively(projectDir) + val pomXml = File(projectDir, "pom.xml") + assertTrue(pomXml.isFile) + pomXml.apply { + writeText(readText().replace("\$dokka_version", currentDokkaVersion)) + } + } + + @Test + fun run() { + val result = ProcessBuilder().directory(projectDir) + .command(mavenBinaryFile.absolutePath, "dokka:dokka", "-U", "-e").start().awaitProcessResult() + + assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)") + + val extensionLoadedRegex = Regex("""Extension: org\.jetbrains\.dokka\.base\.DokkaBase""") + val amountOfExtensionsLoaded = extensionLoadedRegex.findAll(result.output).count() + + assertTrue( + amountOfExtensionsLoaded > 10, + "Expected more than 10 extensions being present (found $amountOfExtensionsLoaded)" + ) + + val undocumentedReportRegex = Regex("""Undocumented:""") + val amountOfUndocumentedReports = undocumentedReportRegex.findAll(result.output).count() + assertTrue( + amountOfUndocumentedReports > 0, + "Expected at least one report of undocumented code (found $amountOfUndocumentedReports)" + ) + + val undocumentedJavaReportRegex = Regex("""Undocumented: it\.basic\.java""") + val amountOfUndocumentedJavaReports = undocumentedJavaReportRegex.findAll(result.output).count() + assertTrue( + amountOfUndocumentedJavaReports > 0, + "Expected at least one report of undocumented java code (found $amountOfUndocumentedJavaReports)" + ) + + val dokkaOutputDir = File(projectDir, "output") + assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory") + + val imagesDir = File(dokkaOutputDir, "images") + assertTrue(imagesDir.isDirectory, "Missing images directory") + + val scriptsDir = File(dokkaOutputDir, "scripts") + assertTrue(scriptsDir.isDirectory, "Missing scripts directory") + + val stylesDir = File(dokkaOutputDir, "styles") + assertTrue(stylesDir.isDirectory, "Missing styles directory") + + val navigationHtml = File(dokkaOutputDir, "navigation.html") + assertTrue(navigationHtml.isFile, "Missing navigation.html") + + projectDir.allHtmlFiles().forEach { file -> + assertContainsNoErrorClass(file) + assertNoUnresolvedLInks(file) + } + + } +} -- cgit From 304b644dffac5dec74ae2e47cbb1917fab90b66a Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Fri, 10 Jul 2020 13:51:35 +0200 Subject: MavenIntegrationTest: Let all fields be private --- .../kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'integration-tests/maven/src/integrationTest') diff --git a/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt b/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt index e52debf4..8690d5d6 100644 --- a/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt +++ b/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt @@ -10,9 +10,9 @@ import kotlin.test.assertTrue class MavenIntegrationTest : AbstractIntegrationTest() { - val currentDokkaVersion: String = checkNotNull(System.getenv("DOKKA_VERSION")) + private val currentDokkaVersion: String = checkNotNull(System.getenv("DOKKA_VERSION")) - val mavenBinaryFile: File = File(checkNotNull(System.getenv("MVN_BINARY_PATH"))) + private val mavenBinaryFile: File = File(checkNotNull(System.getenv("MVN_BINARY_PATH"))) @BeforeTest fun prepareProjectFiles() { -- cgit From 34e696f92aaa3802f13a0074003bc8957218aeba Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Tue, 14 Jul 2020 11:36:47 +0200 Subject: Refactor and add integration tests --- .../dokka/it/maven/MavenIntegrationTest.kt | 98 +++++++++++++++++----- runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 15 ++-- 2 files changed, 82 insertions(+), 31 deletions(-) (limited to 'integration-tests/maven/src/integrationTest') diff --git a/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt b/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt index 8690d5d6..86cc2f41 100644 --- a/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt +++ b/integration-tests/maven/src/integrationTest/kotlin/org/jetbrains/dokka/it/maven/MavenIntegrationTest.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.it.maven import org.jetbrains.dokka.it.AbstractIntegrationTest import org.jetbrains.dokka.it.awaitProcessResult +import org.jetbrains.dokka.it.ProcessResult import java.io.File import kotlin.test.BeforeTest import kotlin.test.Test @@ -26,10 +27,84 @@ class MavenIntegrationTest : AbstractIntegrationTest() { } @Test - fun run() { + fun `dokka dokka`() { val result = ProcessBuilder().directory(projectDir) .command(mavenBinaryFile.absolutePath, "dokka:dokka", "-U", "-e").start().awaitProcessResult() + diagnosticAsserts(result) + + val dokkaOutputDir = File(projectDir, "output") + assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory") + + val imagesDir = File(dokkaOutputDir, "images") + assertTrue(imagesDir.isDirectory, "Missing images directory") + + val scriptsDir = File(dokkaOutputDir, "scripts") + assertTrue(scriptsDir.isDirectory, "Missing scripts directory") + + val stylesDir = File(dokkaOutputDir, "styles") + assertTrue(stylesDir.isDirectory, "Missing styles directory") + + val navigationHtml = File(dokkaOutputDir, "navigation.html") + assertTrue(navigationHtml.isFile, "Missing navigation.html") + + projectDir.allHtmlFiles().forEach { file -> + assertContainsNoErrorClass(file) + assertNoUnresolvedLInks(file) + } + } + + @Test + fun `dokka javadoc`() { + val result = ProcessBuilder().directory(projectDir) + .command(mavenBinaryFile.absolutePath, "dokka:javadoc", "-U", "-e").start().awaitProcessResult() + + diagnosticAsserts(result) + + val dokkaOutputDir = File(projectDir, "output") + assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory") + + val scriptsDir = File(dokkaOutputDir, "jquery") + assertTrue(scriptsDir.isDirectory, "Missing jquery directory") + + val stylesDir = File(dokkaOutputDir, "resources") + assertTrue(stylesDir.isDirectory, "Missing resources directory") + + projectDir.allHtmlFiles().forEach { file -> + assertContainsNoErrorClass(file) + assertNoUnresolvedLInks(file) + } + } + + @Test + fun `dokka javadocJar`() { + val result = ProcessBuilder().directory(projectDir) + .command(mavenBinaryFile.absolutePath, "dokka:javadocJar", "-U", "-e").start().awaitProcessResult() + + diagnosticAsserts(result) + + val dokkaOutputDir = File(projectDir, "output") + assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory") + + val scriptsDir = File(dokkaOutputDir, "jquery") + assertTrue(scriptsDir.isDirectory, "Missing jquery directory") + + val stylesDir = File(dokkaOutputDir, "resources") + assertTrue(stylesDir.isDirectory, "Missing resources directory") + + val dokkaTargetDir = File(projectDir, "target") + assertTrue(dokkaOutputDir.isDirectory, "Missing dokka target directory") + + val jarFile = File(dokkaTargetDir, "it-maven-1.0-SNAPSHOT-javadoc.jar") + assertTrue(jarFile.isFile, "Missing dokka jar file") + + projectDir.allHtmlFiles().forEach { file -> + assertContainsNoErrorClass(file) + assertNoUnresolvedLInks(file) + } + } + + private fun diagnosticAsserts(result: ProcessResult) { assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)") val extensionLoadedRegex = Regex("""Extension: org\.jetbrains\.dokka\.base\.DokkaBase""") @@ -53,26 +128,5 @@ class MavenIntegrationTest : AbstractIntegrationTest() { amountOfUndocumentedJavaReports > 0, "Expected at least one report of undocumented java code (found $amountOfUndocumentedJavaReports)" ) - - val dokkaOutputDir = File(projectDir, "output") - assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory") - - val imagesDir = File(dokkaOutputDir, "images") - assertTrue(imagesDir.isDirectory, "Missing images directory") - - val scriptsDir = File(dokkaOutputDir, "scripts") - assertTrue(scriptsDir.isDirectory, "Missing scripts directory") - - val stylesDir = File(dokkaOutputDir, "styles") - assertTrue(stylesDir.isDirectory, "Missing styles directory") - - val navigationHtml = File(dokkaOutputDir, "navigation.html") - assertTrue(navigationHtml.isFile, "Missing navigation.html") - - projectDir.allHtmlFiles().forEach { file -> - assertContainsNoErrorClass(file) - assertNoUnresolvedLInks(file) - } - } } diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index 5b904dce..514df151 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -52,7 +52,7 @@ class ExternalDocumentationLinkBuilder : DokkaConfiguration.ExternalDocumentatio override var packageListUrl: URL? = null } -abstract class AbstractDokkaMojo : AbstractMojo() { +abstract class AbstractDokkaMojo(private val defaultDokkaPlugins: List) : AbstractMojo() { class SourceRoot : DokkaConfiguration.SourceRoot { @Parameter(required = true) override var path: String = "" @@ -166,7 +166,8 @@ abstract class AbstractDokkaMojo : AbstractMojo() { var failOnWarning: Boolean = DokkaDefaults.failOnWarning @Parameter - open var dokkaPlugins: List = emptyList() + var dokkaPlugins: List = emptyList() + get() = field + defaultDokkaPlugins protected abstract fun getOutDir(): String @@ -315,7 +316,7 @@ abstract class AbstractDokkaMojo : AbstractMojo() { requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true ) -class DokkaMojo : AbstractDokkaMojo() { +class DokkaMojo : AbstractDokkaMojo(emptyList()) { @Parameter(required = true, defaultValue = "\${project.basedir}/target/dokka") var outputDir: String = "" @@ -329,12 +330,10 @@ class DokkaMojo : AbstractDokkaMojo() { requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true ) -class DokkaJavadocMojo : AbstractDokkaMojo() { +class DokkaJavadocMojo : AbstractDokkaMojo(listOf(javadocDependency)) { @Parameter(required = true, defaultValue = "\${project.basedir}/target/dokkaJavadoc") var outputDir: String = "" - override var dokkaPlugins = super.dokkaPlugins + javadocDependency - override fun getOutDir() = outputDir } @@ -345,7 +344,7 @@ class DokkaJavadocMojo : AbstractDokkaMojo() { requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true ) -class DokkaJavadocJarMojo : AbstractDokkaMojo() { +class DokkaJavadocJarMojo : AbstractDokkaMojo(listOf(javadocDependency)) { @Parameter(required = true, defaultValue = "\${project.basedir}/target/dokkaJavadocJar") var outputDir: String = "" @@ -392,8 +391,6 @@ class DokkaJavadocJarMojo : AbstractDokkaMojo() { override fun getOutDir() = outputDir - override var dokkaPlugins = super.dokkaPlugins + javadocDependency - override fun execute() { super.execute() if (!File(outputDir).exists()) { -- cgit