propensive/probably

Make assertion predicates optional and repeated arguments

Closed this issue · 1 comments

At the moment, tests must be defined with either assert or check (which are a statement and an expression, respectively) and take a predicate to be run on the test definition. But sometimes we don't want to check any predicate: we just want to time how long it takes for the test to run, and know whether it throws an exception (or not).

It would be useful to have syntax like this:

test("do something") {
  shouldNotThrow()
}.assert()
test("do something") {
  shouldNotThrow()
}.check()

which would record the fact the test has run, with its timings, and whether it threw an exception, but there would be no pass/fail result.

Furthermore, it would be useful to be able to define multiple predicates in the same test, for example:

test("result is in range") {
  getResult()
}.assert(_ >= 0.0, _ <= 1.0)

which would be equivalent to running, { v => v >= 0.0 && v <= 1.0 }, but would record a result which tells the user which predicate fails.

wi101 commented

Will give it a try