diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-07-10 12:34:15 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-07-13 14:23:08 +0200 |
commit | e940349980c40f87309c9ae80593519952d9dd7f (patch) | |
tree | 2ef3954c341bf8280907a48606ae2649dc9c2d14 /integration-tests/src/main/kotlin/org/jetbrains/dokka/it | |
parent | 7b78890681ba81f1e38f5868fe9e6162efc540c0 (diff) | |
download | dokka-e940349980c40f87309c9ae80593519952d9dd7f.tar.gz dokka-e940349980c40f87309c9ae80593519952d9dd7f.tar.bz2 dokka-e940349980c40f87309c9ae80593519952d9dd7f.zip |
Implement basic assertNoUnresolvedHref
Diffstat (limited to 'integration-tests/src/main/kotlin/org/jetbrains/dokka/it')
-rw-r--r-- | integration-tests/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt b/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt index 4af523a2..0a83045e 100644 --- a/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt +++ b/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt @@ -1,9 +1,11 @@ package org.jetbrains.dokka.it +import org.jsoup.Jsoup import org.junit.Rule import org.junit.rules.TemporaryFolder import java.io.File import kotlin.test.assertFalse +import kotlin.test.assertTrue abstract class AbstractIntegrationTest { @@ -36,4 +38,30 @@ abstract class AbstractIntegrationTest { "Unexpected unresolved link in ${file.path}\n" + fileText ) } + + protected fun assertNoHrefToMissingLocalFileOrDirectory( + file: File, fileExtensions: Set<String> = setOf("html") + ) { + val fileText = file.readText() + val html = Jsoup.parse(fileText) + html.allElements.toList().forEach { element -> + val href = element.attr("href") ?: return@forEach + + if (href.startsWith("#")) return@forEach + if (href.startsWith("https")) return@forEach + if (href.startsWith("http")) return@forEach + + val targetFile = File(file.parent, href) + if (targetFile.extension.isNotEmpty() && targetFile.extension !in fileExtensions) return@forEach + + if ( + targetFile.extension.isEmpty() || targetFile.extension == "html" && !href.startsWith("#")) { + assertTrue( + targetFile.exists(), + "${file.relativeTo(projectDir).path}: href=\"$href\"\n" + + "file does not exist: ${targetFile.relativeTo(projectDir).path}" + ) + } + } + } } |