Browse thread
[Caml-list] Exceptions Handling and Unit Testing.
- chris.danx
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | chris.danx <chris.danx@n...> |
| Subject: | [Caml-list] Exceptions Handling and Unit Testing. |
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