Skip to content

Commit

Permalink
Show arguments in multi-failure summary
Browse files Browse the repository at this point in the history
Resolves #30
  • Loading branch information
BenWoodworth committed Aug 29, 2024
1 parent 7ac9c41 commit b1b2633
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/commonMain/kotlin/ParameterizeFailedError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ internal inline val ParameterizeFailedError.commonMessage
append(" ...")
}
}

failure.arguments.forEach { argument ->
append("\n\t\t")
append(argument)
}
}

if (recordedFailures.size < failureCount) {
Expand Down
40 changes: 35 additions & 5 deletions src/commonTest/kotlin/ParameterizeFailedErrorSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ParameterizeFailedErrorSpec {
)

val error = ParameterizeFailedError(
failures.map { ParameterizeFailure(it, arguments) },
failures.map { ParameterizeFailure(it, emptyList()) },
failureCount = 3,
iterationCount = 7,
completedEarly = false
Expand All @@ -96,7 +96,7 @@ class ParameterizeFailedErrorSpec {
val failures = listOf(NullMessage(), EmptyMessage(), BlankMessage())

val error = ParameterizeFailedError(
failures.map { ParameterizeFailure(it, arguments) },
failures.map { ParameterizeFailure(it, emptyList()) },
failureCount = 3,
iterationCount = 7,
completedEarly = false
Expand All @@ -122,7 +122,7 @@ class ParameterizeFailedErrorSpec {
)

val error = ParameterizeFailedError(
failures.map { ParameterizeFailure(it, arguments) },
failures.map { ParameterizeFailure(it, emptyList()) },
failureCount = 3,
iterationCount = 7,
completedEarly = false
Expand All @@ -146,7 +146,7 @@ class ParameterizeFailedErrorSpec {
)

val error = ParameterizeFailedError(
failures.map { ParameterizeFailure(it, arguments) },
failures.map { ParameterizeFailure(it, emptyList()) },
failureCount = 1,
iterationCount = 7,
completedEarly = false
Expand All @@ -164,7 +164,7 @@ class ParameterizeFailedErrorSpec {
@Test
fun message_failure_list_should_end_with_an_ellipsis_if_not_all_failures_were_recorded() {
val error = ParameterizeFailedError(
List(2) { i -> ParameterizeFailure(Throwable("Failure $i"), arguments) },
List(2) { i -> ParameterizeFailure(Throwable("Failure $i"), emptyList()) },
failureCount = 3,
iterationCount = 7,
completedEarly = false
Expand All @@ -180,6 +180,36 @@ class ParameterizeFailedErrorSpec {
assertEquals(expectedMessage, error.message)
}

@Test
fun message_failure_arguments_list_after_failure_message() {
val failures = listOf(
IllegalStateException("Failure 0"),
AssertionError("Failure 1"),
IllegalArgumentException("Failure 2")
)

val error = ParameterizeFailedError(
failures.mapIndexed { index, it -> ParameterizeFailure(it, arguments.take(index)) },
failureCount = 3,
iterationCount = 7,
completedEarly = false
)

// Tabs for indentation, since that's how the stack traces print.
// Simple name, since the fully qualified name will be shown in the suppressed failures
val expectedMessage = """
Failed 3/7 cases
${'\t'}${failures[0]::class.simpleName}: Failure 0
${'\t'}${failures[1]::class.simpleName}: Failure 1
${'\t'}${'\t'}${arguments[0]}
${'\t'}${failures[2]::class.simpleName}: Failure 2
${'\t'}${'\t'}${arguments[0]}
${'\t'}${'\t'}${arguments[1]}
""".trimIndent()

assertEquals(expectedMessage, error.message)
}

@Test
fun recorded_failures_should_be_added_to_suppressed_exceptions_as_the_cause_in_an_augmented_failure() {
val failures = List(20) { i -> Throwable("Failure $i") }
Expand Down

0 comments on commit b1b2633

Please sign in to comment.