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

assertEquals produces unhelpful diff for large values #480

Closed
mvalle opened this issue Jan 12, 2022 · 4 comments
Closed

assertEquals produces unhelpful diff for large values #480

mvalle opened this issue Jan 12, 2022 · 4 comments

Comments

@mvalle
Copy link

mvalle commented Jan 12, 2022

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)
   ...,
+  ...,
   ...
@kschwarz1116
Copy link

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.

@mzuehlke
Copy link
Contributor

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

@tgodzik
Copy link
Contributor

tgodzik commented Apr 19, 2024

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 tgodzik closed this as completed Apr 19, 2024
@mzuehlke
Copy link
Contributor

The mentioned PR got merged before M8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants