From 7afcabffec7117caa703d03e9d8631cec974a7b8 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 21 May 2019 08:01:35 +0300 Subject: [PATCH] Change implementation of assertFailsWith to make it inline The function 'assertFailsWith' itself was moved to common. --- gradle.properties | 4 +- .../src/main/kotlin/kotlin/test/Assertions.kt | 38 +++++++------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6cd7068f51b..c576d8544b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,8 +20,8 @@ buildKotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds remoteRoot=konan_tests kotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_Compiler),number:1.3.50-dev-328,branch:default:true,pinned:true/artifacts/content/maven kotlinVersion=1.3.50-dev-328 -kotlinStdlibRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_Compiler),number:1.3.50-dev-328,branch:default:true,pinned:true/artifacts/content/maven -kotlinStdlibVersion=1.3.50-dev-328 +kotlinStdlibRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_Compiler),number:1.3.50-dev-368,branch:default:true,pinned:true/artifacts/content/maven +kotlinStdlibVersion=1.3.50-dev-368 testKotlinCompilerVersion=1.3.50-dev-328 # See https://teamcity.jetbrains.com/project.html?projectId=Kotlin_KotlinNativeShared&tab=projectOverview sharedRepo=https://dl.bintray.com/jetbrains/kotlin-native-dependencies diff --git a/runtime/src/main/kotlin/kotlin/test/Assertions.kt b/runtime/src/main/kotlin/kotlin/test/Assertions.kt index 044f0978dcb..bddcf004857 100644 --- a/runtime/src/main/kotlin/kotlin/test/Assertions.kt +++ b/runtime/src/main/kotlin/kotlin/test/Assertions.kt @@ -22,30 +22,20 @@ public actual inline fun todo(block: () -> Unit) { println("TODO") } -/** - * Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. - * - * If the assertion fails, the specified [message] is used unless it is null as a prefix for the failure message. - * - * @return An exception of the expected exception type [T] that successfully caught. - * The returned exception can be inspected further, for example by asserting its property values. - */ -public actual fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T { - try { - block() - } catch (e: Throwable) { - if (exceptionClass.isInstance(e)) { - @Suppress("UNCHECKED_CAST") - return e as T - } - - @Suppress("INVISIBLE_MEMBER") - asserter.fail(messagePrefix(message) + "Expected an exception of ${exceptionClass.qualifiedName} to be thrown, but was $e") - } - - @Suppress("INVISIBLE_MEMBER") - val msg = messagePrefix(message) - asserter.fail(msg + "Expected an exception of ${exceptionClass.qualifiedName} to be thrown, but was completed successfully.") +@PublishedApi +internal actual fun checkResultIsFailure(exceptionClass: KClass, message: String?, blockResult: Result): T { + blockResult.fold( + onSuccess = { + asserter.fail(messagePrefix(message) + "Expected an exception of ${exceptionClass.qualifiedName} to be thrown, but was completed successfully.") + }, + onFailure = { e -> + if (exceptionClass.isInstance(e)) { + @Suppress("UNCHECKED_CAST") + return e as T + } + asserter.fail(messagePrefix(message) + "Expected an exception of ${exceptionClass.qualifiedName} to be thrown, but was $e") + } + ) } internal actual fun lookupAsserter(): Asserter = DefaultAsserter \ No newline at end of file