-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathLinkToExcludedSymbolTest.kt
More file actions
79 lines (72 loc) · 2.77 KB
/
Copy pathLinkToExcludedSymbolTest.kt
File metadata and controls
79 lines (72 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package markdown
import org.jetbrains.dokka.DokkaException
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import utils.TestOutputWriterPlugin
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue
/**
* A KDoc link to a symbol that is excluded from the documentation (suppressed, `internal`,
* deprecated when `skipDeprecated` is on, etc.) resolves to a valid `DRI` during analysis,
* but the symbol has no page. Such a link must not be rendered as a working `<a>` link to a
* non-existent page, and Dokka should warn the developer about it (#4448).
*/
class LinkToExcludedSymbolTest : BaseAbstractTest() {
private val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
private val source = """
|/src/main/kotlin/test/Test.kt
|package test
|
|internal class Hidden
|
|/**
| * See [Hidden] for details.
| */
|public class Public
""".trimMargin()
@Test
fun `link to excluded symbol is rendered as unresolved span and warns`() {
val writerPlugin = TestOutputWriterPlugin()
testInline(source, configuration, pluginOverrides = listOf(writerPlugin)) {
renderingStage = { _, _ ->
val content = writerPlugin.writer.contents.getValue("root/test/-public/index.html")
assertTrue(
content.contains("""data-unresolved-link="test/Hidden///PointingToDeclaration/""""),
"Expected an unresolved-link span for the excluded symbol, but got:\n$content"
)
assertFalse(
content.contains(Regex("""<a [^>]*href="[^"]*Hidden""")),
"A link to an excluded symbol must not be rendered as a working <a> link:\n$content"
)
assertTrue(
logger.warnMessages.any { it.contains("test/Hidden") && it.contains("Couldn't resolve link") },
"Expected a warning about the unresolved link, but got: ${logger.warnMessages}"
)
}
}
}
@Test
fun `link to excluded symbol fails the build when failOnWarning is enabled`() {
val failOnWarningConfiguration = dokkaConfiguration {
failOnWarning = true
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
assertFailsWith<DokkaException> {
testInline(source, failOnWarningConfiguration) {}
}
}
}