diff options
author | Szymon Świstun <sswistun@virtuslab.com> | 2020-02-25 17:22:51 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-02-27 10:06:41 +0100 |
commit | c5b4475e4adf5f5168b6131df78970dc06d470a2 (patch) | |
tree | 8b238d5e9302e4768efa0e06129c8b63b8769181 /plugins/base/src/test/kotlin/expect | |
parent | 951768d7203baa33568e9b713053f30bc9153c4e (diff) | |
download | dokka-c5b4475e4adf5f5168b6131df78970dc06d470a2.tar.gz dokka-c5b4475e4adf5f5168b6131df78970dc06d470a2.tar.bz2 dokka-c5b4475e4adf5f5168b6131df78970dc06d470a2.zip |
output comparing
Diffstat (limited to 'plugins/base/src/test/kotlin/expect')
-rw-r--r-- | plugins/base/src/test/kotlin/expect/ExpectTest.kt | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/plugins/base/src/test/kotlin/expect/ExpectTest.kt b/plugins/base/src/test/kotlin/expect/ExpectTest.kt new file mode 100644 index 00000000..c014c65f --- /dev/null +++ b/plugins/base/src/test/kotlin/expect/ExpectTest.kt @@ -0,0 +1,63 @@ +package expect + +import org.jetbrains.dokka.utilities.DokkaConsoleLogger +import org.junit.Test +import testApi.testRunner.AbstractCoreTest +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths +import java.util.concurrent.TimeUnit + +class ExpectTest : AbstractCoreTest() { + + private fun generateOutput(path: Path): Path? { + val config = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf(path.asString()) + } + } + } + + var result: Path? = null + testFromData(config, cleanupOutput = false) { + renderingStage = { _, context -> result = Paths.get(context.configuration.outputDir) } + } + return result + } + + private fun compareOutput(expected: Path, obtained: Path?, gitTimeout: Long = 500) { + obtained?.let { path -> + val gitCompare = ProcessBuilder( + "git", + "--no-pager", + "diff", + expected.asString(), + path.asString() + ).also { DokkaConsoleLogger.info("git diff command: ${it.command().joinToString(" ")}") } + .start() + + assert(gitCompare.waitFor(gitTimeout, TimeUnit.MILLISECONDS)) { "Git timed out after $gitTimeout" } + gitCompare.inputStream.bufferedReader().lines().forEach { DokkaConsoleLogger.info(it) } + gitCompare.errorStream.bufferedReader().lines().forEach { DokkaConsoleLogger.info(it) } + assert(gitCompare.exitValue() == 0) { "${path.fileName}: outputs don't match" } + } ?: throw AssertionError("obtained path is null") + } + + @Test + fun expectTest() { + val logger = DokkaConsoleLogger + val sources = Paths.get("src/test", "resources", "expect") + + Files.list(sources).forEach { p -> + val expectOut = p.resolve("out") + val testOut = generateOutput(p.resolve("src")) + .also { logger.info("Test out: ${it?.asString()}") } + + compareOutput(expectOut, testOut) + } + } + + fun Path.asString() = toAbsolutePath().normalize().toString() + +}
\ No newline at end of file |