aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-02-28 13:30:51 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-04 14:28:14 +0100
commit763f53987fe803eac412d8549ba2e07ef9560107 (patch)
treee29c7b9b94ae687bc9384c8c3eda4a9f44f8a288
parent33d67aae63986687f0eff9228cfc9f9d5da6d61e (diff)
downloaddokka-763f53987fe803eac412d8549ba2e07ef9560107.tar.gz
dokka-763f53987fe803eac412d8549ba2e07ef9560107.tar.bz2
dokka-763f53987fe803eac412d8549ba2e07ef9560107.zip
Output writer for renderer tests
-rw-r--r--plugins/base/src/test/kotlin/utils/TestOutputWriter.kt27
1 files changed, 27 insertions, 0 deletions
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<DokkaBase>().outputWriter with writer }
+}
+
+class TestOutputWriter(private val failOnOverwrite: Boolean): OutputWriter {
+ val contents: Map<String, String> get() = _contents
+
+ private val _contents = mutableMapOf<String, String>()
+
+ 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(), "")
+}