Skip to content

Commit

Permalink
Add comments explaining lack of contracts for Executable parameter
Browse files Browse the repository at this point in the history
Follow-up on #3259
  • Loading branch information
marcphilipp committed Dec 13, 2024
1 parent 1b4dce5 commit ebf60bb
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ fun assertNotNull(
* @see Assertions.assertThrows
*/
inline fun <reified T : Throwable> assertThrows(executable: () -> Unit): T {
// no contract for `executable` because it is expected to throw an exception instead
// of being executed completely (see https://youtrack.jetbrains.com/issue/KT-27748)
val throwable: Throwable? =
try {
executable()
Expand Down Expand Up @@ -314,6 +316,8 @@ inline fun <reified T : Throwable> assertThrows(
): T {
contract {
callsInPlace(message, AT_MOST_ONCE)
// no contract for `executable` because it is expected to throw an exception instead
// of being executed completely (see https://youtrack.jetbrains.com/issue/KT-27748)
}

val throwable: Throwable? =
Expand Down Expand Up @@ -499,7 +503,10 @@ fun <R> assertTimeout(
fun <R> assertTimeoutPreemptively(
timeout: Duration,
executable: () -> R
): R = Assertions.assertTimeoutPreemptively(timeout, executable)
): R =
// no contract for `executable` because it might be interrupted and throw an exception
// (see https://youtrack.jetbrains.com/issue/KT-27748)
Assertions.assertTimeoutPreemptively(timeout, executable)

/**
* Example usage:
Expand All @@ -516,7 +523,10 @@ fun <R> assertTimeoutPreemptively(
timeout: Duration,
message: String,
executable: () -> R
): R = Assertions.assertTimeoutPreemptively(timeout, executable, message)
): R =
// no contract for `executable` because it might be interrupted and throw an exception
// (see https://youtrack.jetbrains.com/issue/KT-27748)
Assertions.assertTimeoutPreemptively(timeout, executable, message)

/**
* Example usage:
Expand All @@ -537,6 +547,8 @@ fun <R> assertTimeoutPreemptively(
): R {
contract {
callsInPlace(message, AT_MOST_ONCE)
// no contract for `executable` because it might be interrupted and throw an exception
// (see https://youtrack.jetbrains.com/issue/KT-27748)
}

return Assertions.assertTimeoutPreemptively(timeout, executable, message)
Expand Down

0 comments on commit ebf60bb

Please sign in to comment.