Skip to content

Commit

Permalink
Reintroduce better string inequality error msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
valencik committed Apr 15, 2022
1 parent 1503667 commit b28073f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions munit/shared/src/main/scala/munit/Compare.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,18 @@ trait Compare[A, B] {
)(loc)

// Attempt 3: string comparison is not working, unconditionally fail the test.
assertions.failComparison(
s"values are not equal even if they have the same `toString()`: $obtained",
obtained,
expected
)(loc)
if (obtained.toString() == expected.toString())
assertions.failComparison(
s"values are not equal even if they have the same `toString()`: $obtained",
obtained,
expected
)(loc)
else
assertions.failComparison(
s"values are not equal, even if their text representation only differs in leading/trailing whitespace and ANSI escape characters: $obtained",
obtained,
expected
)(loc)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object AssertionsFrameworkSuite
|=> Diff (- obtained, + expected)
|-a.A()
|+b.B()
|==> failure munit.AssertionsFrameworkSuite.toString-has-different-whitespace - /scala/munit/AssertionsFrameworkSuite.scala:39 values are not equal even if they have the same `toString()`: foo
|==> failure munit.AssertionsFrameworkSuite.toString-has-different-whitespace - /scala/munit/AssertionsFrameworkSuite.scala:39 values are not equal, even if their text representation only differs in leading/trailing whitespace and ANSI escape characters: foo
|38: test("toString-has-different-whitespace") {
|39: assertEquals[Any, Any]("foo", "foo ")
|40: }
Expand Down

0 comments on commit b28073f

Please sign in to comment.