caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Exceptions Handling and Unit Testing.
@ 2004-09-20 20:21 chris.danx
  2004-09-20 20:27 ` chris.danx
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: chris.danx @ 2004-09-20 20:21 UTC (permalink / raw)
  To: Caml Mailing List

Hi,

As I've been writing test code, I've noticed some patterns which occur 
over and over again.  All of the patterns have to do with construction. 
  The tests currently follow one of two patterns.

The first deals with conditions on which construction of an object 
should fail, and looks like this

let some_construction_test some_op input exception error_msg =
   try
     let x = some_op input
     in
       OUnit.assert_failure error_msg
   with
     exception -> ()


The second deals with asserting a set of conditions are true after a 
successful construction and would like something like this.

let
   some_test some_op input (conditions : ('a -> 'b -> bool) * ('a * 'b * 
string) list) =
   let p = some_op input
   in
     check_conditions p conditions ...

The second can be coded easily in Ocaml and is included just to set the 
scene as it where.  Ideally I'd like to implement the first pattern but 
don't know how.  The problem is the exception!  It should work ok for an 
exception (constructor) that has no arguments, but doesn't seem to work 
for exceptions with arguments.  OUnit already provides assert_failure 
which takes an expression and checks it raises a specific exception 
however it has the same problem.

Handling

exception Rtfm_error of string;;

is a problem but

exception Rtfm_error;;

is not.

Am I missing something?  Is this possible?  I looked to see if the 
exception could be caught and checked at runtime, but the support in the 
OCaml libraries for exceptions seems weak.  The exception can be caught 
via a catch all pattern, but there seems to be no way to determine if it 
is the desired exception (a success) or another exception (an error).


Cheers,
Chris

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-09-21 23:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-20 20:21 [Caml-list] Exceptions Handling and Unit Testing chris.danx
2004-09-20 20:27 ` chris.danx
2004-09-20 20:59 ` art yerkes
2004-09-21  8:24 ` Damien Doligez
2004-09-21 23:23 ` chris.danx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).