Skip to content

Wrong line number in stack trace from assert #422

@mbovel

Description

@mbovel

I get strange stack traces with the following source and tests:

// Main.scala
package example

object Main:
  def f = throw new Exception("Oh no")
  def main =  println("Hello world!")
// MainSuite.scala
package example

class MainSuite extends munit.FunSuite:
  import Main.*

  /**
   * Checks that f returns 42. Checks that f returns 42. Checks that f returns 42. Checks that f returns 42.
   */
  test("f returns 42") {
    assert(f == 42) // MainSuite.scala:13
  }

  /**
   * Checks that f still returns 42.
   */
  test("f still returns 42") {
    assert(f == 42) // MainSuite.scala:20
  }

  /**
   * Checks that f really returns 42.
   */
  test("f really returns 42") {
    assertEquals(f, 42) // MainSuite.scala:27
  }

  /**
   * Checks that f undeniably returns 42.
   */
  test("f undeniably returns 42") {
    assertEquals(f, 42) // MainSuite.scala:34
  }
==> X example.MainSuite.f returns 42  0.007s java.lang.Exception: Oh no
    at munit.FunSuite.assert(FunSuite.scala:11)
    at example.MainSuite.$init$$$anonfun$1(MainSuite.scala:29)
==> X example.MainSuite.f still returns 42  0.001s java.lang.Exception: Oh no
    at munit.FunSuite.assert(FunSuite.scala:11)
    at example.MainSuite.$init$$$anonfun$2(MainSuite.scala:29)
==> X example.MainSuite.f really returns 42  0.0s java.lang.Exception: Oh no
    at example.Main$.f(Main.scala:5)
    at example.MainSuite.$init$$$anonfun$3(MainSuite.scala:25)
==> X example.MainSuite.f undeniably returns 42  0.0s java.lang.Exception: Oh no
    at example.Main$.f(Main.scala:5)
    at example.MainSuite.$init$$$anonfun$4(MainSuite.scala:32)

MainSuite.scala:29 is the middle of the last comment ( * Checks that f undeniably returns 42.). Increasing or decreasing the comments length impacts the line number.

Stack traces originating from assertEquals are correct.

Setup: MUnit 0.7.29, SBT 1.5.5, Scala 3.0.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions