aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2021-03-01 12:01:41 +0100
committerGitHub <noreply@github.com>2021-03-01 12:01:41 +0100
commitab853a866c40771e84a3235f40575efe04c435c5 (patch)
tree81f4df0d5ead3bac649f9ac61a04864ebcb57c44 /plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt
parentce962389afe86c0d54a08df942e564a077b25c3f (diff)
downloaddokka-ab853a866c40771e84a3235f40575efe04c435c5.tar.gz
dokka-ab853a866c40771e84a3235f40575efe04c435c5.tar.bz2
dokka-ab853a866c40771e84a3235f40575efe04c435c5.zip
Add explicit exceptions in markdown and allow for empty link destinations (#1757)
Diffstat (limited to 'plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt')
-rw-r--r--plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt93
1 files changed, 93 insertions, 0 deletions
diff --git a/plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt b/plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt
new file mode 100644
index 00000000..b9837750
--- /dev/null
+++ b/plugins/base/src/test/kotlin/transformers/InvalidContentModuleAndPackageDocumentationReaderTest.kt
@@ -0,0 +1,93 @@
+package transformers
+
+import org.jetbrains.dokka.base.transformers.documentables.ModuleAndPackageDocumentationReader
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.utilities.DokkaConsoleLogger
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import testApi.testRunner.TestDokkaConfigurationBuilder
+import testApi.testRunner.dModule
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+
+class InvalidContentModuleAndPackageDocumentationReaderTest : AbstractContextModuleAndPackageDocumentationReaderTest() {
+
+ private val includeA by lazy { temporaryDirectory.resolve("includeA.md").toFile() }
+ private val includeB by lazy { temporaryDirectory.resolve("includeB.md").toFile() }
+
+ @BeforeEach
+ fun materializeInclude() {
+ includeA.writeText(
+ """
+ Invalid random stuff
+
+ # Module moduleA
+ Simple stuff
+ """.trimIndent()
+ )
+ includeB.writeText(
+ """
+ # Module moduleB
+ ###
+ """.trimIndent()
+ )
+ }
+
+ private val configurationBuilderA = TestDokkaConfigurationBuilder().apply {
+ moduleName = "moduleA"
+ }
+ private val configurationBuilderB = TestDokkaConfigurationBuilder().apply {
+ moduleName = "moduleB"
+ }
+
+ private val sourceSetA by configurationBuilderA.sourceSet {
+ includes = listOf(includeA.canonicalPath)
+ }
+
+ private val sourceSetB by configurationBuilderB.sourceSet {
+ includes = listOf(includeB.canonicalPath)
+ }
+
+ private val contextA by lazy {
+ DokkaContext.create(
+ configuration = configurationBuilderA.build(),
+ logger = DokkaConsoleLogger,
+ pluginOverrides = emptyList()
+ )
+ }
+ private val contextB by lazy {
+ DokkaContext.create(
+ configuration = configurationBuilderB.build(),
+ logger = DokkaConsoleLogger,
+ pluginOverrides = emptyList()
+ )
+ }
+
+ private val readerA by lazy { ModuleAndPackageDocumentationReader(contextA) }
+ private val readerB by lazy { ModuleAndPackageDocumentationReader(contextB) }
+
+
+ @Test
+ fun `parsing should fail with a message when documentation is in not proper format`() {
+ val exception =
+ runCatching { readerA[dModule(name = "moduleA", sourceSets = setOf(sourceSetA))] }.exceptionOrNull()
+ assertEquals(
+ "Unexpected classifier: \"Invalid\", expected either \"Module\" or \"Package\". \n" +
+ "For more information consult the specification: https://kotlinlang.org/docs/reference/kotlin-doc.html#module-and-package-documentation",
+ exception?.message
+ )
+ }
+
+ @Test
+ fun `parsing should fail with a message where it encountered error and why`() {
+ val exception =
+ runCatching { readerB[dModule(name = "moduleB", sourceSets = setOf(sourceSetB))] }.exceptionOrNull()?.message!!
+
+ //I don't want to assert whole message since it contains a path to a temporary folder
+ assertTrue(exception.contains("Wrong AST Tree. Header does not contain expected content in "))
+ assertTrue(exception.contains("includeB.md"))
+ assertTrue(exception.contains("element starts from offset 0 and ends 3: ###"))
+ }
+}
+