aboutsummaryrefslogtreecommitdiff
path: root/integration-tests/src/main/kotlin/org/jetbrains/dokka/it
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-07-08 10:47:05 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-07-08 18:59:57 +0200
commitcaf48e76f3bff5e9907cd094cf0719f623e528d5 (patch)
tree554b313645a83749afba1e77af35b930bbf4448f /integration-tests/src/main/kotlin/org/jetbrains/dokka/it
parent6d1e25756c3e8c43ce4d5721e7665f439a19e47c (diff)
downloaddokka-caf48e76f3bff5e9907cd094cf0719f623e528d5.tar.gz
dokka-caf48e76f3bff5e9907cd094cf0719f623e528d5.tar.bz2
dokka-caf48e76f3bff5e9907cd094cf0719f623e528d5.zip
Implement simple MavenIntegrationTest.kt
Diffstat (limited to 'integration-tests/src/main/kotlin/org/jetbrains/dokka/it')
-rw-r--r--integration-tests/src/main/kotlin/org/jetbrains/dokka/it/environmentUtils.kt16
-rw-r--r--integration-tests/src/main/kotlin/org/jetbrains/dokka/it/processUtils.kt51
2 files changed, 67 insertions, 0 deletions
diff --git a/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/environmentUtils.kt b/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/environmentUtils.kt
new file mode 100644
index 00000000..eadf5a8c
--- /dev/null
+++ b/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/environmentUtils.kt
@@ -0,0 +1,16 @@
+package org.jetbrains.dokka.it
+
+import java.io.File
+
+/**
+ * Indicating whether or not the current machine executing the test is a CI
+ */
+val isCI: Boolean get() = System.getenv("CI") == "true"
+
+val isAndroidSdkInstalled: Boolean = System.getenv("ANDROID_SDK_ROOT") != null ||
+ System.getenv("ANDROID_HOME") != null
+
+val isMavenInstalled: Boolean = System.getenv("PATH").orEmpty()
+ .split(File.pathSeparator)
+ .flatMap { pathElement -> File(pathElement).listFiles().orEmpty().toList() }
+ .any { pathElement -> "mvn" == pathElement.name }
diff --git a/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/processUtils.kt b/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/processUtils.kt
new file mode 100644
index 00000000..d2c048ac
--- /dev/null
+++ b/integration-tests/src/main/kotlin/org/jetbrains/dokka/it/processUtils.kt
@@ -0,0 +1,51 @@
+package org.jetbrains.dokka.it
+
+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()
+}