[Pkg-ocaml-maint-commits] [approx] 07/08: relax check for Invalid_argument exception
Eric Cooper
ecc at cmu.edu
Sat Jun 20 17:51:28 UTC 2015
This is an automated email from the git hooks/post-receive script.
ecc-guest pushed a commit to branch upstream
in repository approx.
commit f289e798d29e4f686f602cf45bb465dfed8d0205
Author: Eric Cooper <ecc at cmu.edu>
Date: Fri Jun 19 22:55:10 2015 -0400
relax check for Invalid_argument exception
In OCaml 4.02, String.sub raises Invalid_argument("String.sub / Bytes.sub")
Rather than check for it exactly using assert_raises,
only check that the constructor is Invalid_argument.
---
tests/testlib.ml | 12 ++++++++++++
tests/util_test.ml | 14 +++++++-------
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/tests/testlib.ml b/tests/testlib.ml
index 0649f3e..6e0fc07 100644
--- a/tests/testlib.ml
+++ b/tests/testlib.ml
@@ -2,6 +2,7 @@
Copyright (C) 2015 Eric C. Cooper <ecc at cmu.edu>
Released under the GNU General Public License *)
+open OUnit
open Printf
let p_bool = sprintf "%b"
@@ -16,3 +17,14 @@ let p_opt pf = function | Some x -> pf x | None -> "-"
let p_exn = Printexc.to_string
let tear_down _ _ = ()
+
+let assert_invalid ?msg f =
+ let result =
+ try f (); None
+ with e -> Some e
+ in
+ match result with
+ | None ->
+ assert_failure "expected Invalid_argument exception, but no exception was raised."
+ | Some (Invalid_argument _) -> ()
+ | Some e -> assert_failure ("expected Invalid_argument exception, but " ^ p_exn e ^ " was raised.")
diff --git a/tests/util_test.ml b/tests/util_test.ml
index 363c802..d5623a3 100644
--- a/tests/util_test.ml
+++ b/tests/util_test.ml
@@ -73,15 +73,15 @@ let suite = [
Some 6, None, "abcdef", "";
Some 6, Some 6, "abcdef", ""]
@
- map (fun (from, until, str, e) ->
+ map (fun (from, until, str) ->
sprintf "(substring %s %s %s)"
(p_opt p_int from) (p_opt p_int until) (p_str str) >::
- (fun _ -> assert_raises e (fun () -> Util.substring ?from ?until str)))
- [None, Some 7, "abcdef", Invalid_argument "String.sub";
- Some 0, Some 7, "abcdef", Invalid_argument "String.sub";
- Some 1, None, "", Invalid_argument "String.sub";
- Some 7, None, "abcdef", Invalid_argument "String.sub";
- Some 4, Some 3, "abcdef", Invalid_argument "String.sub"];
+ (fun _ -> assert_invalid (fun () -> Util.substring ?from ?until str)))
+ [None, Some 7, "abcdef";
+ Some 0, Some 7, "abcdef";
+ Some 1, None, "";
+ Some 7, None, "abcdef";
+ Some 4, Some 3, "abcdef"];
"split_tests" >:::
map (fun (c, str, res) ->
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/approx.git
More information about the Pkg-ocaml-maint-commits
mailing list