munit icon indicating copy to clipboard operation
munit copied to clipboard

assertEquals produces unhelpful diff for large values

Open mvalle opened this issue 3 years ago • 1 comments

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)
   ...,
+  ...,
   ...

mvalle avatar Jan 12 '22 12:01 mvalle

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.

kschwarz1116 avatar May 08 '22 01:05 kschwarz1116

#640 has probably solved this issue and it can be closed

mzuehlke avatar Apr 19 '24 11:04 mzuehlke

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

tgodzik avatar Apr 19 '24 12:04 tgodzik

The mentioned PR got merged before M8

mzuehlke avatar Apr 19 '24 15:04 mzuehlke