1998-11-11 07:35:48 -08:00
|
|
|
(* Test bound checks with ocamlopt *)
|
|
|
|
|
|
|
|
let a = [| 0; 1; 2 |]
|
|
|
|
|
1998-11-12 02:22:02 -08:00
|
|
|
let trail = ref []
|
|
|
|
|
1998-11-11 07:35:48 -08:00
|
|
|
let test n =
|
|
|
|
let result =
|
|
|
|
try
|
1998-11-12 02:22:02 -08:00
|
|
|
trail := n :: !trail; a.(n); "doesn't fail"
|
1998-11-11 07:35:48 -08:00
|
|
|
with Invalid_argument s ->
|
|
|
|
(* Check well-formedness of s *)
|
2003-11-21 08:06:33 -08:00
|
|
|
if String.length s = 19
|
|
|
|
&& s = "index out of bounds"
|
1998-11-11 07:35:48 -08:00
|
|
|
then "fails"
|
|
|
|
else "bad Invalid_argument"
|
|
|
|
| _ -> "bad exception"
|
|
|
|
in
|
|
|
|
print_int n; print_string ": "; print_string result; print_newline()
|
|
|
|
|
|
|
|
let _ =
|
1998-11-12 02:22:02 -08:00
|
|
|
test 0; test 1; test 2; test 3; test 4; test (-1);
|
|
|
|
Gc.full_major();
|
|
|
|
print_string "Trail:";
|
|
|
|
List.iter (fun n -> print_string " "; print_int n) !trail;
|
|
|
|
print_newline()
|
|
|
|
|
1998-11-11 07:35:48 -08:00
|
|
|
|