Skip to content

clues for assertEquals #913

@scarf005

Description

@scarf005
//> using test.dep org.scalameta::munit::1.1.0

class Suite extends munit.FunSuite:
    def add(a: Int, b: Int): Int = a + b

    test("example"):
        List(
          1 -> 1,
          1 -> 2,
        ).foreach { (a, b) => assertEquals(clue(add(a, b)), 2) }
$ scala --cli-version 1.7.1 test myfile.scala
Compiling project (Scala 3.6.4, JVM (23))
Compiled project (Scala 3.6.4, JVM (23))
Suite:
==> X Suite.example  0.042s munit.ComparisonFailException: /run/media/home/scarf/repo/etc/kata/myfile.scala:10
9:           1 -> 2,
10:        ).foreach { (a, b) => assertEquals(clue(add(a, b)), 2) }
values are not the same
=> Obtained
3
=> Diff (- expected, + obtained)
-2
+3
    at munit.FunSuite.assertEquals(FunSuite.scala:13)
    at Suite.$init$$$anonfun$1$$anonfun$1(myfile.scala:10)
    at scala.collection.immutable.List.foreach(List.scala:334)
    at Suite.$init$$$anonfun$1(myfile.scala:10)

when using foreach with assertEquals, error messages could be hard to process as it's not possible to see which params were passed to (in this case, 1 and 2). would be great if params could be (somehow) captured for assertEquals too like assert:

//> using dep org.scalameta::munit::1.1.0

class Suite extends munit.FunSuite:
    def add(a: Int, b: Int): Int = a + b

    test("example"):
        List(
          1 -> 1,
          1 -> 2,
        ).foreach { (a, b) => assert(clue(add(clue(a), clue(b))) == clue(2)) }
Suite:
==> X Suite.example  0.024s munit.FailException: /run/media/home/scarf/repo/etc/kata/myfile.scala:10 assertion failed
9:           1 -> 2,
10:        ).foreach { (a, b) => assert(clue(add(clue(a), clue(b))) == clue(2)) }
Clues {
  a: Int = 1
  b: Int = 2
  add(clue(a), clue(b)): Int = 3
  2: Int = 2
}
    at munit.FunSuite.assert(FunSuite.scala:13)
    at Suite.$init$$$anonfun$1$$anonfun$1(myfile.scala:10)
    at scala.collection.immutable.List.foreach(List.scala:334)
    at Suite.$init$$$anonfun$1(myfile.scala:10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions