alpaca-lang / alpaca

Functional programming inspired by ML for the Erlang VM
Other
1.44k stars 47 forks source link

Use values to signify test pass/fail rather than exceptions #244

Closed lpil closed 4 years ago

lpil commented 6 years ago

Taken from here: https://github.com/alpaca-lang/alpaca_lib/pull/10#discussion_r161378639

Currently a test is considered a failure if it throws an exception.

Instead we could have a test be a zero arity function that returns some data structure representing success and failure. The test construct can then throw or not throw the appropriate eunit exception depending on what is returned.

To me it feels like it would be more fitting for an ML language to work with values and pure functions rather than exceptions.

Would also give us a clear way to make multiple assertions in a single test.

module assert

val all : list (fn () -> assertion) -> assertion
let all assertions =
  assertions
    |> list.find (fn testCase -> isFail (testCase ()))
    |> option.orElse Pass