Skip to content

Commit

Permalink
Removed contracts for methods where lambdas may throw exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
awelless committed Sep 8, 2023
1 parent 4d21486 commit 30b9b78
Showing 1 changed file with 7 additions and 29 deletions.
Expand Up @@ -21,7 +21,6 @@ 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 @@ -37,7 +36,7 @@ fun fail(message: String?, throwable: Throwable? = null): Nothing =
@JvmName("fail_nonNullableLambda")
fun fail(message: () -> String): Nothing {
contract {
callsInPlace(message, UNKNOWN)
callsInPlace(message, EXACTLY_ONCE)
}

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

val throwable: Throwable? = try {
executable()
} catch (caught: Throwable) {
Expand All @@ -336,13 +331,8 @@ inline fun <reified T : Throwable> assertThrows(executable: () -> Unit): T {
* ```
* @see Assertions.assertThrows
*/
inline fun <reified T : Throwable> assertThrows(message: String, executable: () -> Unit): T {
contract {
callsInPlace(executable, UNKNOWN)
}

return assertThrows({ message }, executable)
}
inline fun <reified T : Throwable> assertThrows(message: String, executable: () -> Unit): T =
assertThrows({ message }, executable)

/**
* Example usage:
Expand All @@ -356,7 +346,6 @@ inline fun <reified T : Throwable> assertThrows(message: String, executable: ()
*/
inline fun <reified T : Throwable> assertThrows(noinline message: () -> String, executable: () -> Unit): T {
contract {
callsInPlace(executable, UNKNOWN)
callsInPlace(message, AT_MOST_ONCE)
}

Expand Down Expand Up @@ -515,13 +504,8 @@ fun <R> assertTimeout(timeout: Duration, message: () -> String, executable: () -
* @param R the result of the [executable].
*/
@API(status = EXPERIMENTAL, since = "5.5")
fun <R> assertTimeoutPreemptively(timeout: Duration, executable: () -> R): R {
contract {
callsInPlace(executable, UNKNOWN)
}

return Assertions.assertTimeoutPreemptively(timeout, executable)
}
fun <R> assertTimeoutPreemptively(timeout: Duration, executable: () -> R): R =
Assertions.assertTimeoutPreemptively(timeout, executable)

/**
* Example usage:
Expand All @@ -534,13 +518,8 @@ fun <R> assertTimeoutPreemptively(timeout: Duration, executable: () -> R): R {
* @param R the result of the [executable].
*/
@API(status = EXPERIMENTAL, since = "5.5")
fun <R> assertTimeoutPreemptively(timeout: Duration, message: String, executable: () -> R): R {
contract {
callsInPlace(executable, UNKNOWN)
}

return Assertions.assertTimeoutPreemptively(timeout, executable, message)
}
fun <R> assertTimeoutPreemptively(timeout: Duration, message: String, executable: () -> R): R =
Assertions.assertTimeoutPreemptively(timeout, executable, message)

/**
* Example usage:
Expand All @@ -555,7 +534,6 @@ fun <R> assertTimeoutPreemptively(timeout: Duration, message: String, executable
@API(status = EXPERIMENTAL, since = "5.5")
fun <R> assertTimeoutPreemptively(timeout: Duration, message: () -> String, executable: () -> R): R {
contract {
callsInPlace(executable, UNKNOWN)
callsInPlace(message, AT_MOST_ONCE)
}

Expand Down

0 comments on commit 30b9b78

Please sign in to comment.