Skip to content

Commit

Permalink
Specify lambda InvocationKind explicitly for assertThrows methods
Browse files Browse the repository at this point in the history
  • Loading branch information
awelless committed Aug 27, 2023
1 parent 43c08ea commit ff9fd39
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -21,6 +21,7 @@ import java.util.function.Supplier
import java.util.stream.Stream
import kotlin.contracts.InvocationKind.AT_MOST_ONCE
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.InvocationKind.UNKNOWN
import kotlin.contracts.contract

/**
Expand All @@ -35,7 +36,7 @@ fun fail(message: String?, throwable: Throwable? = null): Nothing =
@JvmName("fail_nonNullableLambda")
fun fail(message: () -> String): Nothing {
contract {
callsInPlace(message)
callsInPlace(message, UNKNOWN)
}

return Assertions.fail<Nothing>(message)
Expand Down Expand Up @@ -308,7 +309,7 @@ inline fun <reified T : Any> assertInstanceOf(actual: Any?, noinline messageSupp
*/
inline fun <reified T : Throwable> assertThrows(executable: () -> Unit): T {
contract {
callsInPlace(executable)
callsInPlace(executable, UNKNOWN)
}

val throwable: Throwable? = try {
Expand Down Expand Up @@ -336,7 +337,7 @@ inline fun <reified T : Throwable> assertThrows(executable: () -> Unit): T {
*/
inline fun <reified T : Throwable> assertThrows(message: String, executable: () -> Unit): T {
contract {
callsInPlace(executable)
callsInPlace(executable, UNKNOWN)
}

return assertThrows({ message }, executable)
Expand All @@ -354,7 +355,7 @@ inline fun <reified T : Throwable> assertThrows(message: String, executable: ()
*/
inline fun <reified T : Throwable> assertThrows(noinline message: () -> String, executable: () -> Unit): T {
contract {
callsInPlace(executable)
callsInPlace(executable, UNKNOWN)
callsInPlace(message, AT_MOST_ONCE)
}

Expand Down

0 comments on commit ff9fd39

Please sign in to comment.