diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-08-05 15:37:54 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-14 14:16:41 +0200 |
commit | dd6bbdb88b0e4aaefde6598fee605714a3a516d8 (patch) | |
tree | 3eecaede6ea45afb38447e197645f418c573c751 /test-tools/src/main/kotlin | |
parent | 8af7e4cade0a872ed638acf42d8c474415af290f (diff) | |
download | dokka-dd6bbdb88b0e4aaefde6598fee605714a3a516d8.tar.gz dokka-dd6bbdb88b0e4aaefde6598fee605714a3a516d8.tar.bz2 dokka-dd6bbdb88b0e4aaefde6598fee605714a3a516d8.zip |
Add tools for easier content test debugging
Diffstat (limited to 'test-tools/src/main/kotlin')
-rw-r--r-- | test-tools/src/main/kotlin/matchers/content/contentMatchers.kt | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/test-tools/src/main/kotlin/matchers/content/contentMatchers.kt b/test-tools/src/main/kotlin/matchers/content/contentMatchers.kt index 2284c88d..f42e28f3 100644 --- a/test-tools/src/main/kotlin/matchers/content/contentMatchers.kt +++ b/test-tools/src/main/kotlin/matchers/content/contentMatchers.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.test.tools.matchers.content +import org.jetbrains.dokka.model.asPrintableTree import org.jetbrains.dokka.pages.ContentComposite import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.pages.ContentText @@ -20,9 +21,13 @@ open class NodeMatcher<T : ContentNode>( try { assertions() } catch (e: AssertionError) { - throw MatcherError(e.message.orEmpty(), this@NodeMatcher, cause = e) + throw MatcherError( + "${e.message.orEmpty()}\nin node:\n${node.debugRepresentation()}", + this@NodeMatcher, + cause = e + ) } - } ?: throw MatcherError("Expected ${kclass.simpleName} but got: $node", this) + } ?: throw MatcherError("Expected ${kclass.simpleName} but got:\n${node.debugRepresentation()}", this) } } @@ -63,7 +68,7 @@ private class TextMatcherState( val anchor: TextMatcher ) : MatchWalkerState() { override fun next(node: ContentNode): MatchWalkerState { - node as? ContentText ?: throw MatcherError("Expected text: \"$text\" but got $node", anchor) + node as? ContentText ?: throw MatcherError("Expected text: \"$text\" but got\n${node.debugRepresentation()}", anchor) val trimmed = node.text.trim() return when { text == trimmed -> rest.pop() @@ -77,7 +82,7 @@ private class TextMatcherState( private class EmptyMatcherState(val parent: CompositeMatcher<*>) : MatchWalkerState() { override fun next(node: ContentNode): MatchWalkerState { - throw MatcherError("Unexpected $node", parent, anchorAfter = true) + throw MatcherError("Unexpected node:\n${node.debugRepresentation()}", parent, anchorAfter = true) } override fun finish() = Unit @@ -121,7 +126,6 @@ private class FurtherSiblings(val list: List<MatcherElement>, val parent: Compos } - internal fun MatcherElement.toDebugString(anchor: MatcherElement?, anchorAfter: Boolean): String { fun Appendable.append(element: MatcherElement, ownPrefix: String, childPrefix: String) { if (anchor != null) { @@ -156,6 +160,18 @@ internal fun MatcherElement.toDebugString(anchor: MatcherElement?, anchorAfter: return buildString { append(this@toDebugString, "", "") } } +private fun ContentNode.debugRepresentation() = asPrintableTree { element -> + append(if (element is ContentText) """"${element.text}"""" else element::class.simpleName) + append( + " { " + + "kind=${element.dci.kind}, " + + "dri=${element.dci.dri}, " + + "style=${element.style}, " + + "sourceSets=${element.sourceSets} " + + "}" + ) +} + data class MatcherError( override val message: String, val anchor: MatcherElement, |