eed3si9n/expecty

Request: add support for messages

edreyer opened this issue · 1 comments

Thanks for the nice library!

At times, a user supplied message can provide more context, or motivation, for the assertion failure.

The motivation for this is that many people use assert outside of dev or test suites. For example, in DataBricks (Spark) notebooks where a human context for the assertion failure provides real value.

With that in mind, please provide add an API similar to:
e.g. Predef.assert(assertion: Boolean, message: => Any)

I agree we should provide Predef-like API.

Here are comparison of Predef.assert vs Expecty.assert

scala> Predef.assert(foo == 2, "something something")
java.lang.AssertionError: assertion failed: something something
  at scala.Predef$.assert(Predef.scala:223)
  ... 36 elided

scala> Predef.assert(foo == 2)
java.lang.AssertionError: assertion failed
  at scala.Predef$.assert(Predef.scala:208)
  ... 36 elided

scala> com.eed3si9n.expecty.Expecty.assert(foo == 2)
java.lang.AssertionError:

com.eed3si9n.expecty.Expecty.assert(foo == 2)
                                    |   |
                                    1   false

  at com.eed3si9n.expecty.Expecty$ExpectyListener.expressionRecorded(Expecty.scala:25)
  at com.eed3si9n.expecty.RecorderRuntime.recordExpression(RecorderRuntime.scala:34)
  ... 36 elided

I guess I should add "assertion failed" and the custom message afterwards.