aboutsummaryrefslogtreecommitdiff
path: root/integration-tests/src/main
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-07-10 12:34:15 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-07-13 14:23:08 +0200
commite940349980c40f87309c9ae80593519952d9dd7f (patch)
tree2ef3954c341bf8280907a48606ae2649dc9c2d14 /integration-tests/src/main
parent7b78890681ba81f1e38f5868fe9e6162efc540c0 (diff)
downloaddokka-e940349980c40f87309c9ae80593519952d9dd7f.tar.gz
dokka-e940349980c40f87309c9ae80593519952d9dd7f.tar.bz2
dokka-e940349980c40f87309c9ae80593519952d9dd7f.zip
Implement basic assertNoUnresolvedHref
Diffstat (limited to 'integration-tests/src/main')
-rw-r--r--integration-tests/src/main/kotlin/org/jetbrains/dokka/it/AbstractIntegrationTest.kt28
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}"
+ )
+ }
+ }
+ }
}