Skip to content

Commit

Permalink
Don't throw MultipleFailuresError if failure list is empty
Browse files Browse the repository at this point in the history
In a nested context this was causing failures to be dropped since it was
mapping to an empty list.

Fixes #314
  • Loading branch information
evant committed Aug 24, 2020
1 parent 18a6bed commit f6a967b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions assertk/src/commonMain/kotlin/assertk/failure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ internal class SoftFailure(
}

private fun compositeErrorMessage(errors: List<Throwable>): Throwable {
return if (errors.size == 1) {
errors.first()
} else {
MultipleFailuresError(message, errors).apply {
return when(errors.size) {
0 -> AssertionFailedError(message)
1 -> errors.first()
else -> MultipleFailuresError(message, errors).apply {
errors.forEach(this::addSuppressed)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ class IterableTest {
)
}

@Test fun exactly_too_few_inside_all_fails() {
val error = assertFails {
assertThat(listOf(5, 4, 3) as Iterable<Int>).all {
exactly(2) { it.isGreaterThan(2) }
}
}
assertEquals(
"""expected to pass exactly 2 times""".trimMargin(), error.message
)
}

@Test fun exactly_times_passed_passes() {
assertThat(listOf(0, 1, 2) as Iterable<Int>).exactly(2) { it.isGreaterThan(0) }
}
Expand Down

0 comments on commit f6a967b

Please sign in to comment.