Make more lambda-taking functions in kotlin-test inline-only

So that the lambda can contain non-local control flow, such as suspend
calls. Inline-only helps preserving line numbers in the failed assertion
stack traces.

KT-44717
This commit is contained in:
Ilya Gorbunov
2021-03-06 06:29:48 +03:00
committed by TeamCityServer
parent 66a29c70bf
commit ca99fc4fed
2 changed files with 57 additions and 11 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -8,6 +8,8 @@
package kotlin.test
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.internal.*
import kotlin.reflect.*
@@ -51,6 +53,43 @@ fun <T : Throwable> assertFailsWithNoInline(exceptionClass: KClass<T>, block: ()
fun <T : Throwable> assertFailsWithNoInline(exceptionClass: KClass<T>, message: String?, block: () -> Unit): T =
assertFailsWith(exceptionClass, message, block)
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertTrue")
fun assertTrueNoInline(message: String? = null, block: () -> Boolean) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertTrue(block(), message)
}
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertFalse")
fun assertFalseNoInline(message: String? = null, block: () -> Boolean) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertFalse(block(), message)
}
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertNotNull")
fun <T : Any, R> assertNotNullNoInline(actual: T?, message: String? = null, block: (T) -> R) {
contract { returns() implies (actual != null) }
asserter.assertNotNull(message, actual)
if (actual != null) {
block(actual)
}
}
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("expect")
fun <T> expectNoInline(expected: T, block: () -> T) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertEquals(expected, block())
}
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("expect")
fun <T> expectNoInline(expected: T, message: String?, block: () -> T) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertEquals(expected, block(), message)
}
/**
* Takes the given [block] of test code and _doesn't_ execute it.