Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Exceptions Handling and Unit Testing.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-20 (20:21)
From: chris.danx <chris.danx@n...>
Subject: [Caml-list] Exceptions Handling and Unit Testing.

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 =
     let x = some_op input
       OUnit.assert_failure error_msg
     exception -> ()

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

   some_test some_op input (conditions : ('a -> 'b -> bool) * ('a * 'b * 
string) list) =
   let p = some_op input
     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.


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).


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: