From: "chris.danx" <chris.danx@ntlworld.com>
To: Caml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] Exceptions Handling and Unit Testing.
Date: Mon, 20 Sep 2004 21:21:26 +0100 [thread overview]
Message-ID: <414F3BC6.2010705@ntlworld.com> (raw)
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
next reply other threads:[~2004-09-20 20:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-20 20:21 chris.danx [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=414F3BC6.2010705@ntlworld.com \
--to=chris.danx@ntlworld.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox