diff --git a/munit/shared/src/main/scala/munit/Compare.scala b/munit/shared/src/main/scala/munit/Compare.scala index 40b59795..15745d7a 100644 --- a/munit/shared/src/main/scala/munit/Compare.scala +++ b/munit/shared/src/main/scala/munit/Compare.scala @@ -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) } } diff --git a/tests/shared/src/main/scala/munit/AssertionsFrameworkSuite.scala b/tests/shared/src/main/scala/munit/AssertionsFrameworkSuite.scala index e1f94dd9..1f4c624b 100644 --- a/tests/shared/src/main/scala/munit/AssertionsFrameworkSuite.scala +++ b/tests/shared/src/main/scala/munit/AssertionsFrameworkSuite.scala @@ -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: }