Skip to content

Commit

Permalink
More correct string inequality error message (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
raboof authored Oct 5, 2021
1 parent 773d668 commit b8bcd93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 12 additions & 5 deletions munit/shared/src/main/scala/munit/Assertions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,18 @@ trait Assertions extends MacroCompat.CompileErrorMacro {
munitPrint(clue),
printObtainedAsStripMargin = false
)
failComparison(
s"values are not equal even if they have the same `toString()`: $obtained",
obtained,
expected
)
if (obtained.toString() == expected.toString())
failComparison(
s"values are not equal even if they have the same `toString()`: $obtained",
obtained,
expected
)
else
failComparison(
s"values are not equal, even if their text representation only differs in leading/trailing whitespace and ANSI escape characters: $obtained",
obtained,
expected
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class AssertionsFrameworkSuite extends FunSuite {
}
assertEquals[Any, Any](a.A(), b.A())
}

test("toString-has-different-whitespace") {
assertEquals[Any, Any]("foo", "foo ")
}
}

object AssertionsFrameworkSuite
Expand All @@ -57,5 +61,9 @@ 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 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: }
|""".stripMargin
)

0 comments on commit b8bcd93

Please sign in to comment.