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 23, 2020
1 parent 18a6bed commit 4b0685f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 11 additions & 5 deletions assertk/src/commonMain/kotlin/assertk/failure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ internal class SoftFailure(
}

private fun compositeErrorMessage(errors: List<Throwable>): Throwable {
return if (errors.size == 1) {
errors.first()
} else {
MultipleFailuresError(message, errors).apply {
errors.forEach(this::addSuppressed)
return when {
errors.isEmpty() -> {
AssertionFailedError(message)
}
errors.size == 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 4b0685f

Please sign in to comment.