munit
munit copied to clipboard
assertEquals produces unhelpful diff for large values
The assertEquals
function generally produces a useful diff. But if the size of the objects that are being compared is too large, it produces an output that doesn't say anything useful about the assertion failure.
Example test:
test("assertEquals on long lists") {
val a = (1 to 158).toList
val b = (1 to 158).toList ++ List(159)
assertEquals(a, b)
}
output:
=> Diff (- obtained, + expected)
...,
+ ...,
...
I was able to override the limit in the following way:
package example
import munit.{FunSuite, Printer}
import munit.internal.console.Printers
class FunTest extends FunSuite {
def longPrinter = new Printer {
def print(value: Any, out: StringBuilder, indent: Int): Boolean = false
override def height = 200
}
override def munitPrint(clue: => Any): String = {
clue match {
case message: String => message
case value => Printers.print(value, longPrinter)
}
}
test("assertEquals on long lists") {
val a = (1 to 158).toList
val b = (1 to 158).toList ++ List(159)
assertEquals(a, b)
}
}
Probably wouldn't hurt to add documentation around this.
#640 has probably solved this issue and it can be closed
Looks like it, we can close if the result is not satisfactory let us know! If it's not in M12 it will be in the RC
The mentioned PR got merged before M8