Skip to content

Commit ebf60bb

Browse files
committed
Add comments explaining lack of contracts for Executable parameter
Follow-up on #3259
1 parent 1b4dce5 commit ebf60bb

File tree

1 file changed

+14
-2
lines changed
  • junit-jupiter-api/src/main/kotlin/org/junit/jupiter/api

1 file changed

+14
-2
lines changed

junit-jupiter-api/src/main/kotlin/org/junit/jupiter/api/Assertions.kt

+14-2
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ fun assertNotNull(
268268
* @see Assertions.assertThrows
269269
*/
270270
inline fun <reified T : Throwable> assertThrows(executable: () -> Unit): T {
271+
// no contract for `executable` because it is expected to throw an exception instead
272+
// of being executed completely (see https://youtrack.jetbrains.com/issue/KT-27748)
271273
val throwable: Throwable? =
272274
try {
273275
executable()
@@ -314,6 +316,8 @@ inline fun <reified T : Throwable> assertThrows(
314316
): T {
315317
contract {
316318
callsInPlace(message, AT_MOST_ONCE)
319+
// no contract for `executable` because it is expected to throw an exception instead
320+
// of being executed completely (see https://youtrack.jetbrains.com/issue/KT-27748)
317321
}
318322

319323
val throwable: Throwable? =
@@ -499,7 +503,10 @@ fun <R> assertTimeout(
499503
fun <R> assertTimeoutPreemptively(
500504
timeout: Duration,
501505
executable: () -> R
502-
): R = Assertions.assertTimeoutPreemptively(timeout, executable)
506+
): R =
507+
// no contract for `executable` because it might be interrupted and throw an exception
508+
// (see https://youtrack.jetbrains.com/issue/KT-27748)
509+
Assertions.assertTimeoutPreemptively(timeout, executable)
503510

504511
/**
505512
* Example usage:
@@ -516,7 +523,10 @@ fun <R> assertTimeoutPreemptively(
516523
timeout: Duration,
517524
message: String,
518525
executable: () -> R
519-
): R = Assertions.assertTimeoutPreemptively(timeout, executable, message)
526+
): R =
527+
// no contract for `executable` because it might be interrupted and throw an exception
528+
// (see https://youtrack.jetbrains.com/issue/KT-27748)
529+
Assertions.assertTimeoutPreemptively(timeout, executable, message)
520530

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

542554
return Assertions.assertTimeoutPreemptively(timeout, executable, message)

0 commit comments

Comments
 (0)