Skip to content

Commit

Permalink
Add test case for #96
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbull committed Apr 10, 2024
1 parent 3a50dfa commit c39888e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public inline fun <V, E> binding(crossinline block: BindingScope<E>.() -> V): Re
return with(BindingScopeImpl<E>()) {
try {
Ok(block())
} catch (ex: BindException) {
} catch (_: BindException) {
result!!
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,24 @@ class BindingTest {
actual = result,
)
}

@Test
fun runCatchingInsideBindingDoesNotSwallow() {
fun squareNumber(): Result<Int, BindingError> = throw RuntimeException()

val squaredNumbers = binding<List<Int>, BindingError> {
val result: Result<List<Int>, Throwable> = runCatching {
(0..<10).map { number ->
squareNumber().bind()
}
}

result.mapError { BindingError }.bind()
}

assertEquals(
expected = Err(BindingError),
actual = squaredNumbers,
)
}
}

0 comments on commit c39888e

Please sign in to comment.