Change implementation of assertFailsWith to make it inline

The function 'assertFailsWith' itself was moved to common.
This commit is contained in:
Ilya Gorbunov
2019-05-21 08:01:35 +03:00
committed by Pavel Punegov
parent 31df1ddc52
commit 7afcabffec
2 changed files with 16 additions and 26 deletions
+2 -2
View File
@@ -20,8 +20,8 @@ buildKotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds
remoteRoot=konan_tests 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 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 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 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-328 kotlinStdlibVersion=1.3.50-dev-368
testKotlinCompilerVersion=1.3.50-dev-328 testKotlinCompilerVersion=1.3.50-dev-328
# See https://teamcity.jetbrains.com/project.html?projectId=Kotlin_KotlinNativeShared&tab=projectOverview # See https://teamcity.jetbrains.com/project.html?projectId=Kotlin_KotlinNativeShared&tab=projectOverview
sharedRepo=https://dl.bintray.com/jetbrains/kotlin-native-dependencies sharedRepo=https://dl.bintray.com/jetbrains/kotlin-native-dependencies
@@ -22,30 +22,20 @@ public actual inline fun todo(block: () -> Unit) {
println("TODO") println("TODO")
} }
/** @PublishedApi
* Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. internal actual fun <T : Throwable> checkResultIsFailure(exceptionClass: KClass<T>, message: String?, blockResult: Result<Unit>): T {
* blockResult.fold(
* If the assertion fails, the specified [message] is used unless it is null as a prefix for the failure message. onSuccess = {
* asserter.fail(messagePrefix(message) + "Expected an exception of ${exceptionClass.qualifiedName} to be thrown, but was completed successfully.")
* @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. onFailure = { e ->
*/ if (exceptionClass.isInstance(e)) {
public actual fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, message: String?, block: () -> Unit): T { @Suppress("UNCHECKED_CAST")
try { return e as T
block() }
} catch (e: Throwable) { asserter.fail(messagePrefix(message) + "Expected an exception of ${exceptionClass.qualifiedName} to be thrown, but was $e")
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.")
} }
internal actual fun lookupAsserter(): Asserter = DefaultAsserter internal actual fun lookupAsserter(): Asserter = DefaultAsserter