kotest
kotest copied to clipboard
Contain exactly more detail (#26)
improve output of shouldContainExactly, try to find matching sublists, just like git diff does
, as follows:
val expected = listOf(sweetGreenApple, sweetRedApple, sweetGreenPear)
val actual = listOf(sweetGreenPear, sweetGreenApple, sweetRedApple)
shouldThrow<AssertionError> {
actual shouldContainExactly expected
}.shouldHaveMessage("""
|Collection should contain exactly: [Fruit(name=apple, color=green, taste=sweet), Fruit(name=apple, color=red, taste=sweet), Fruit(name=pear, color=green, taste=sweet)] but was: [Fruit(name=pear, color=green, taste=sweet), Fruit(name=apple, color=green, taste=sweet), Fruit(name=apple, color=red, taste=sweet)]
|
|Mismatch:
|expected[0] = Fruit(name=pear, color=green, taste=sweet)
|
|Match:
|expected[1] == actual[0]: Fruit(name=apple, color=green, taste=sweet)
|expected[2] == actual[1]: Fruit(name=apple, color=red, taste=sweet)
|
|Mismatch:
|actual[2] = Fruit(name=pear, color=green, taste=sweet)
|
|""".trimMargin())
@AlexCue987 Should this be refactored to use the similarity package now?
@AlexCue987 Should this be refactored to use the similarity package now?
of course, that's the plan. This will add more info to the output. No code will be removed, a couple lines will be added. As this PR is large as is, do we want to make it slightly larger, or should we add similarity in a later PR? WDYT @Kantis ?
so the enhanced message should look like this:
shouldHaveMessage("""
|Collection should contain exactly: [Fruit(name=apple, color=green, taste=sweet), Fruit(name=apple, color=red, taste=sweet), Fruit(name=pear, color=green, taste=sweet)] but was: [Fruit(name=pear, color=green, taste=sweet), Fruit(name=apple, color=green, taste=sweet), Fruit(name=apple, color=red, taste=sweet)]
|
|Mismatch:
|expected[0] = Fruit(name=pear, color=green, taste=sweet)
|
|Match:
|expected[1] == actual[0]: Fruit(name=apple, color=green, taste=sweet)
|expected[2] == actual[1]: Fruit(name=apple, color=red, taste=sweet)
|
|Mismatch:
|actual[2] = Fruit(name=pear, color=green, taste=sweet)
|
| ----- <<< add similarity output here
|""".trimMargin())
There are conflicts on the merge.
There are conflicts on the merge.
just resolved a redeclaration. did I miss any other conflicts?
@AlexCue987 Should this be refactored to use the similarity package now?
this is the PR which adds search for similar elements in the same matcher: https://github.com/kotest/kotest/pull/3910 it adds some other useful output, not replacing the need for this one.
Needs the conflicts fixing.
Closing this PR, to resolve conflicts and re-open it later.