Skip to content

Improve error messages tests by providing unit test support #1965

@felixmulder

Description

@felixmulder

Currently, testing error messages is done by using check files in the ./tests/repl/ dir. This has several drawbacks, one of the largest being that these are hard to keep in sync since they are only tested by diffing.

It would be great to have a unit test that would work along the lines of:

@Test def typeMismatch =
  checkErrors (
    """|class Foo {
       |  def bar: Int = "IIEK"
       |}""".stripMargin,
  )
  .expect { implicit ctx =>
    val defn = ctx.definitions
    TypeMismatch(defn.StringType, defn.IntType) :: Nil
  }

To do this, we need to extend DottyTest and provide the context with a custom reporter that aggregates the errors instead of rendering them to stdout.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions