From c5b4475e4adf5f5168b6131df78970dc06d470a2 Mon Sep 17 00:00:00 2001 From: Szymon Świstun Date: Tue, 25 Feb 2020 17:22:51 +0100 Subject: output comparing --- plugins/base/src/test/kotlin/expect/ExpectTest.kt | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 plugins/base/src/test/kotlin/expect/ExpectTest.kt (limited to 'plugins/base/src/test/kotlin/expect') 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 -- cgit From 971ca471fbca2d382557e8609706eb683a3ada96 Mon Sep 17 00:00:00 2001 From: Szymon Świstun Date: Wed, 26 Feb 2020 11:33:43 +0100 Subject: response to comments --- plugins/base/src/test/kotlin/expect/ExpectTest.kt | 9 +- .../test/resources/expect/test/out/-search.html | 42 ++-- .../expect/test/out/images/arrow_down.svg | 3 +- .../resources/expect/test/out/images/logo-icon.svg | 2 +- .../resources/expect/test/out/images/logo-text.svg | 12 +- .../test/resources/expect/test/out/navigation.html | 16 +- .../test/resources/expect/test/out/root/fn.html | 37 ++-- .../test/resources/expect/test/out/root/index.html | 41 ++-- .../expect/test/out/scripts/navigationLoader.js | 8 +- .../resources/expect/test/out/scripts/pages.js | 6 +- .../resources/expect/test/out/scripts/scripts.js | 18 +- .../resources/expect/test/out/scripts/search.js | 7 +- .../resources/expect/test/out/styles/style.css | 240 ++++++++++----------- 13 files changed, 213 insertions(+), 228 deletions(-) (limited to 'plugins/base/src/test/kotlin/expect') diff --git a/plugins/base/src/test/kotlin/expect/ExpectTest.kt b/plugins/base/src/test/kotlin/expect/ExpectTest.kt index c014c65f..3a85db17 100644 --- a/plugins/base/src/test/kotlin/expect/ExpectTest.kt +++ b/plugins/base/src/test/kotlin/expect/ExpectTest.kt @@ -1,6 +1,5 @@ package expect -import org.jetbrains.dokka.utilities.DokkaConsoleLogger import org.junit.Test import testApi.testRunner.AbstractCoreTest import java.nio.file.Files @@ -34,19 +33,18 @@ class ExpectTest : AbstractCoreTest() { "diff", expected.asString(), path.asString() - ).also { DokkaConsoleLogger.info("git diff command: ${it.command().joinToString(" ")}") } + ).also { logger.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) } + gitCompare.inputStream.bufferedReader().lines().forEach { logger.info(it) } + gitCompare.errorStream.bufferedReader().lines().forEach { logger.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 -> @@ -55,6 +53,7 @@ class ExpectTest : AbstractCoreTest() { .also { logger.info("Test out: ${it?.asString()}") } compareOutput(expectOut, testOut) + testOut?.toFile()?.deleteRecursively() } } diff --git a/plugins/base/src/test/resources/expect/test/out/-search.html b/plugins/base/src/test/resources/expect/test/out/-search.html index 6f6af500..1ee812bb 100644 --- a/plugins/base/src/test/resources/expect/test/out/-search.html +++ b/plugins/base/src/test/resources/expect/test/out/-search.html @@ -1,25 +1,23 @@ - - Search - - - - - - -
-

Search results for

- - -
-
- + + Search + + + + + + +
+

Search results for

+ + +
+
+ diff --git a/plugins/base/src/test/resources/expect/test/out/images/arrow_down.svg b/plugins/base/src/test/resources/expect/test/out/images/arrow_down.svg index d6dedd64..89e7df47 100644 --- a/plugins/base/src/test/resources/expect/test/out/images/arrow_down.svg +++ b/plugins/base/src/test/resources/expect/test/out/images/arrow_down.svg @@ -1,4 +1,3 @@ - + diff --git a/plugins/base/src/test/resources/expect/test/out/images/logo-icon.svg b/plugins/base/src/test/resources/expect/test/out/images/logo-icon.svg index 61606c7e..1b3b3670 100644 --- a/plugins/base/src/test/resources/expect/test/out/images/logo-icon.svg +++ b/plugins/base/src/test/resources/expect/test/out/images/logo-icon.svg @@ -1,3 +1,3 @@ - + diff --git a/plugins/base/src/test/resources/expect/test/out/images/logo-text.svg b/plugins/base/src/test/resources/expect/test/out/images/logo-text.svg index e98992a8..7bf3e6c5 100644 --- a/plugins/base/src/test/resources/expect/test/out/images/logo-text.svg +++ b/plugins/base/src/test/resources/expect/test/out/images/logo-text.svg @@ -1,10 +1,6 @@ - - - - + + + + diff --git a/plugins/base/src/test/resources/expect/test/out/navigation.html b/plugins/base/src/test/resources/expect/test/out/navigation.html index b0f35878..ebff817d 100644 --- a/plugins/base/src/test/resources/expect/test/out/navigation.html +++ b/plugins/base/src/test/resources/expect/test/out/navigation.html @@ -1,14 +1,10 @@