Skip to content

Relax Kotlin contracts for Executable parameters #4481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: marc/jdk17
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions junit-jupiter-api/junit-jupiter-api.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ dependencies {
}

tasks {
compileKotlin {
// https://github.com/junit-team/junit5/issues/4371
compilerOptions.allWarningsAsErrors = false
}
jar {
bundle {
val version = project.version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ inline fun <reified T : Throwable> assertThrows(
@API(status = STABLE, since = "5.11")
inline fun <R> assertDoesNotThrow(executable: () -> R): R {
contract {
callsInPlace(executable, EXACTLY_ONCE)
callsInPlace(executable, AT_MOST_ONCE)
}

return Assertions.assertDoesNotThrow(evaluateAndWrap(executable))
Expand All @@ -374,7 +374,7 @@ inline fun <R> assertDoesNotThrow(
executable: () -> R
): R {
contract {
callsInPlace(executable, EXACTLY_ONCE)
callsInPlace(executable, AT_MOST_ONCE)
}

return assertDoesNotThrow({ message }, executable)
Expand All @@ -397,7 +397,7 @@ inline fun <R> assertDoesNotThrow(
executable: () -> R
): R {
contract {
callsInPlace(executable, EXACTLY_ONCE)
callsInPlace(executable, AT_MOST_ONCE)
callsInPlace(message, AT_MOST_ONCE)
}

Expand All @@ -411,7 +411,7 @@ inline fun <R> assertDoesNotThrow(
@PublishedApi
internal inline fun <R> evaluateAndWrap(executable: () -> R): ThrowingSupplier<R> {
contract {
callsInPlace(executable, EXACTLY_ONCE)
callsInPlace(executable, AT_MOST_ONCE)
}

return try {
Expand Down Expand Up @@ -439,7 +439,7 @@ fun <R> assertTimeout(
executable: () -> R
): R {
contract {
callsInPlace(executable, EXACTLY_ONCE)
callsInPlace(executable, AT_MOST_ONCE)
}

return Assertions.assertTimeout(timeout, executable)
Expand All @@ -463,7 +463,7 @@ fun <R> assertTimeout(
executable: () -> R
): R {
contract {
callsInPlace(executable, EXACTLY_ONCE)
callsInPlace(executable, AT_MOST_ONCE)
}

return Assertions.assertTimeout(timeout, executable, message)
Expand All @@ -487,7 +487,7 @@ fun <R> assertTimeout(
executable: () -> R
): R {
contract {
callsInPlace(executable, EXACTLY_ONCE)
callsInPlace(executable, AT_MOST_ONCE)
callsInPlace(message, AT_MOST_ONCE)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,26 @@ internal class KotlinAssertTimeoutAssertionsTests {
}

@Test
fun `assertTimeout with value initialization in lambda`() {
val value: Int
fun `assertTimeout with value assignment in lambda`() {
var value = 0

assertTimeout(ofMillis(500)) { value = 10 }

assertEquals(10, value)
}

@Test
fun `assertTimeout with message and value initialization in lambda`() {
val value: Int
fun `assertTimeout with message and value assignment in lambda`() {
var value = 0

assertTimeout(ofMillis(500), "message") { value = 10 }

assertEquals(10, value)
}

@Test
fun `assertTimeout with message supplier and value initialization in lambda`() {
val value: Int
fun `assertTimeout with message supplier and value assignment in lambda`() {
var value = 0

@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
val valueInMessageSupplier: Int
Expand Down