vincent-hugot / qtest

Inline (Unit) Tests for OCaml
GNU General Public License v3.0
67 stars 8 forks source link

idea for E #20

Open c-cube opened 8 years ago

c-cube commented 8 years ago

exception tests are not easy, because you can't just use equality (for instance, the string in Invalid_argument might not be specified).

If you don't have a specific idea in mind, I propose the following semantic and syntax:

(*$E
  <exn matcher> <code to test>
*)

where <exn matcher>: exn -> bool pattern matches an exception, and <code to test>: 'a should raise an exception that is validated by <exn matcher>. A block (*$E f g *) would be encoded into

assert_bool "some message"
  ( try g; false with e -> f e )
vincent-hugot commented 8 years ago

Sounds logical.

There hasn't been much need for E tests in Batteries, because there are especially compact patterns for that in simple tests, but I see no reason not to implement them.