From 7196323582dce7ca3f9b07262a1f94ecd8514539 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Mon, 24 Aug 2020 14:02:07 +0200 Subject: - Move `test` projects into semantic parent projects - Implement new `:test-utils` project - Resolve requirement for Android SDK installation --- .../kotlin/org/jetbrains/dokka/test/assertIsInstance.kt | 17 +++++++++++++++++ .../jetbrains/dokka/test/assumeAndroidSdkInstalled.kt | 8 ++++++++ .../kotlin/org/jetbrains/dokka/test/environmentUtils.kt | 9 +++++++++ 3 files changed, 34 insertions(+) create mode 100644 test-utils/src/main/kotlin/org/jetbrains/dokka/test/assertIsInstance.kt create mode 100644 test-utils/src/main/kotlin/org/jetbrains/dokka/test/assumeAndroidSdkInstalled.kt create mode 100644 test-utils/src/main/kotlin/org/jetbrains/dokka/test/environmentUtils.kt (limited to 'test-utils/src/main/kotlin/org/jetbrains/dokka') diff --git a/test-utils/src/main/kotlin/org/jetbrains/dokka/test/assertIsInstance.kt b/test-utils/src/main/kotlin/org/jetbrains/dokka/test/assertIsInstance.kt new file mode 100644 index 00000000..d646d385 --- /dev/null +++ b/test-utils/src/main/kotlin/org/jetbrains/dokka/test/assertIsInstance.kt @@ -0,0 +1,17 @@ +package org.jetbrains.dokka.test + +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract + +@OptIn(ExperimentalContracts::class) +inline fun assertIsInstance(obj: Any?): T { + contract { + returns() implies (obj is T) + } + + if (obj is T) { + return obj + } + + throw AssertionError("Expected instance of type ${T::class.qualifiedName} but found $obj") +} diff --git a/test-utils/src/main/kotlin/org/jetbrains/dokka/test/assumeAndroidSdkInstalled.kt b/test-utils/src/main/kotlin/org/jetbrains/dokka/test/assumeAndroidSdkInstalled.kt new file mode 100644 index 00000000..0c0e6d31 --- /dev/null +++ b/test-utils/src/main/kotlin/org/jetbrains/dokka/test/assumeAndroidSdkInstalled.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka.test + +import org.junit.Assume.assumeTrue + +fun assumeAndroidSdkInstalled() { + if (isCI) return + assumeTrue(isAndroidSdkInstalled) +} diff --git a/test-utils/src/main/kotlin/org/jetbrains/dokka/test/environmentUtils.kt b/test-utils/src/main/kotlin/org/jetbrains/dokka/test/environmentUtils.kt new file mode 100644 index 00000000..e9b7be95 --- /dev/null +++ b/test-utils/src/main/kotlin/org/jetbrains/dokka/test/environmentUtils.kt @@ -0,0 +1,9 @@ +package org.jetbrains.dokka.test + +/** + * 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 -- cgit