diff options
Diffstat (limited to 'integration-tests/cli/src/main/kotlin/org/jetbrains')
-rw-r--r-- | integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/AbstractCliIntegrationTest.kt | 36 | ||||
-rw-r--r-- | integration-tests/cli/src/main/kotlin/org/jetbrains/dokka/it/cli/processUtils.kt | 51 |
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() +} |