Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More correct string inequality error message #427

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)