From 763f53987fe803eac412d8549ba2e07ef9560107 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Fri, 28 Feb 2020 13:30:51 +0100 Subject: Output writer for renderer tests --- .../base/src/test/kotlin/utils/TestOutputWriter.kt | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 plugins/base/src/test/kotlin/utils/TestOutputWriter.kt diff --git a/plugins/base/src/test/kotlin/utils/TestOutputWriter.kt b/plugins/base/src/test/kotlin/utils/TestOutputWriter.kt new file mode 100644 index 00000000..43161929 --- /dev/null +++ b/plugins/base/src/test/kotlin/utils/TestOutputWriter.kt @@ -0,0 +1,27 @@ +package utils + +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.renderers.OutputWriter +import org.jetbrains.dokka.plugability.DokkaPlugin +import java.io.File + +class TestOutputWriterPlugin(failOnOverwrite: Boolean): DokkaPlugin() { + private val writer = TestOutputWriter(failOnOverwrite) + + val testWriter by extending { plugin().outputWriter with writer } +} + +class TestOutputWriter(private val failOnOverwrite: Boolean): OutputWriter { + val contents: Map get() = _contents + + private val _contents = mutableMapOf() + + override fun write(path: String, text: String, ext: String) { + val fullPath = listOf(path, ext).joinToString(separator = ".") + _contents.putIfAbsent(fullPath, text)?.also { + if (failOnOverwrite) throw AssertionError("File $fullPath is being overwritten.") + } + } + + override fun writeResources(pathFrom: String, pathTo: String) = write(pathFrom, File(pathTo).readText(), "") +} -- cgit