aboutsummaryrefslogtreecommitdiff
path: root/integration-tests/cli/src/main
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-07-07 11:08:34 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-07-07 13:31:38 +0200
commitcb20227d354b1b74ca6784d55ea75cc8b5281abd (patch)
tree2284ff9b5535a735655a9ad0ee436f2aa4e68a07 /integration-tests/cli/src/main
parent72e6c72774f65308ce1da807bc0fa5798575d013 (diff)
downloaddokka-cb20227d354b1b74ca6784d55ea75cc8b5281abd.tar.gz
dokka-cb20227d354b1b74ca6784d55ea75cc8b5281abd.tar.bz2
dokka-cb20227d354b1b74ca6784d55ea75cc8b5281abd.zip
Implement simple cli integration test
Diffstat (limited to 'integration-tests/cli/src/main')
-rw-r--r--integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/AbstractCliIntegrationTest.kt36
-rw-r--r--integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/processUtils.kt51
2 files changed, 87 insertions, 0 deletions
diff --git a/integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/AbstractCliIntegrationTest.kt b/integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/AbstractCliIntegrationTest.kt
new file mode 100644
index 00000000..7f6f9433
--- /dev/null
+++ b/integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/AbstractCliIntegrationTest.kt
@@ -0,0 +1,36 @@
+package org.jetbrains.dokka.it.cli
+
+import org.jetbrains.dokka.it.AbstractIntegrationTest
+import java.io.File
+import kotlin.test.BeforeTest
+import kotlin.test.assertTrue
+
+abstract class AbstractCliIntegrationTest : AbstractIntegrationTest() {
+
+ protected val cliJarFile: File by lazy {
+ File(temporaryTestFolder.root, "dokka.jar")
+ }
+
+ protected val basePluginJarFile: File by lazy {
+ File(temporaryTestFolder.root, "base-plugin.jar")
+ }
+
+ @BeforeTest
+ fun copyJarFiles() {
+ val cliJarPathEnvironmentKey = "CLI_JAR_PATH"
+ val cliJarFile = File(System.getenv(cliJarPathEnvironmentKey))
+ assertTrue(
+ cliJarFile.exists() && cliJarFile.isFile,
+ "Missing path to CLI jar System.getenv($cliJarPathEnvironmentKey)"
+ )
+ cliJarFile.copyTo(this.cliJarFile)
+
+ val basePluginPathEnvironmentKey = "BASE_PLUGIN_JAR_PATH"
+ val basePluginJarFile = File(System.getenv(basePluginPathEnvironmentKey))
+ assertTrue(
+ basePluginJarFile.exists() && basePluginJarFile.isFile,
+ "Missing path to base plugin jar System.getenv($basePluginPathEnvironmentKey)"
+ )
+ basePluginJarFile.copyTo(this.basePluginJarFile)
+ }
+}
diff --git a/integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/processUtils.kt b/integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/processUtils.kt
new file mode 100644
index 00000000..d2fa3b31
--- /dev/null
+++ b/integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/processUtils.kt
@@ -0,0 +1,51 @@
+package org.jetbrains.dokka.it.cli
+
+import kotlinx.coroutines.CompletableDeferred
+import kotlinx.coroutines.async
+import kotlinx.coroutines.runBlocking
+import kotlin.concurrent.thread
+
+class ProcessResult(
+ val exitCode: Int,
+ val output: String
+)
+
+fun Process.awaitProcessResult() = runBlocking {
+ val exitCode = async { awaitExitCode() }
+ val output = async { awaitOutput() }
+ ProcessResult(
+ exitCode.await(),
+ output.await()
+ )
+}
+
+private suspend fun Process.awaitExitCode(): Int {
+ val deferred = CompletableDeferred<Int>()
+ thread {
+ try {
+ deferred.complete(this.waitFor())
+ } catch (e: Throwable) {
+ deferred.completeExceptionally(e)
+ }
+ }
+
+ return deferred.await()
+}
+
+private suspend fun Process.awaitOutput(): String {
+ val deferred = CompletableDeferred<String>()
+ thread {
+ try {
+ var string = ""
+ this.inputStream.bufferedReader().forEachLine { line ->
+ println(line)
+ string += line + System.lineSeparator()
+ }
+ deferred.complete(string)
+ } catch (e: Throwable) {
+ deferred.completeExceptionally(e)
+ }
+ }
+
+ return deferred.await()
+}