qtest icon indicating copy to clipboard operation
qtest copied to clipboard

idea for E

Open c-cube opened this issue 10 years ago • 1 comments

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 )

c-cube avatar Sep 20 '15 08:09 c-cube

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.

vincent-hugot avatar Sep 20 '15 11:09 vincent-hugot