From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA05508; Mon, 20 Sep 2004 22:21:27 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA05531 for ; Mon, 20 Sep 2004 22:21:26 +0200 (MET DST) Received: from mta03-svc.ntlworld.com (mta03-svc.ntlworld.com [62.253.162.43]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i8KKLQRB025588 for ; Mon, 20 Sep 2004 22:21:26 +0200 Received: from [80.4.70.84] by mta03-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with ESMTP id <20040920201950.PYGO20874.mta03-svc.ntlworld.com@[80.4.70.84]> for ; Mon, 20 Sep 2004 21:19:50 +0100 Message-ID: <414F3BC6.2010705@ntlworld.com> Date: Mon, 20 Sep 2004 21:21:26 +0100 From: "chris.danx" User-Agent: Mozilla Thunderbird 0.8 (X11/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Caml Mailing List Subject: [Caml-list] Exceptions Handling and Unit Testing. Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 414F3BC6.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; ntlworld:99 ideally:01 rtfm:01 rtfm:01 runtime:01 chris:01 chris:01 bool:01 ocaml:01 ocaml:01 raises:01 assert:02 assert:02 exception:02 exception:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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