2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
13 exception Expected_throw_missing
15 exception Thrown_exception_mismatched
of (exn
* exn
)
17 let expect_throws e f x
=
20 Printf.eprintf
"Error. Did not throw expected: %s\n" (Exn.to_string e
);
24 if Poly.(e
<> err
) then
27 "Error. Expected exn: %s. But got : %s\n"
36 Printf.printf
"Running %s ... %!" name
;
40 let e = Exception.wrap
e in
41 let () = Printf.printf
"Exception %s\n" (Exception.to_string
e) in
43 Printf.printf
"Backtrace %s\n" (Exception.get_backtrace_string
e)
48 Printf.printf
"ok\n%!"
50 Printf.printf
"fail\n%!";
53 (** List.for_all but without shortcircuiting "&&", so runs all failures too. *)
54 let for_all_non_shortcircuit tests f
=
55 List.fold_left tests ~init
:true ~f
:(fun acc test
-> f test
&& acc
)
57 let run_all (tests
: (string * (unit -> bool)) list
) =
58 Printexc.record_backtrace
true;
60 (if for_all_non_shortcircuit tests
run then
65 let run_only tests names
=
69 | _ -> (fun (n
, _) -> List.mem names n ~equal
:String.( = ))
71 let tests = List.filter
tests ~
f in
75 let names = Option.value (List.tl
@@ Array.to_list
Sys.argv
) ~default
:[] in