12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- open Base
- open OUnit2
- module type TESTABLE = sig
- type t
- val equal: t Equal.t
- val to_string: t -> string
- end
- module String_ = struct
- type t = string
- let equal = String.equal
- let to_string x = Printf.sprintf "%S" x
- end
- module Option_(X: TESTABLE) = struct
- type t = X.t option
- let equal = Option.equal X.equal
- let to_string = function
- | Some(x) -> "Some(" ^ X.to_string x ^ ")"
- | None -> "None"
- end
- module List_(X: TESTABLE) = struct
- type t = X.t list
- let equal = List.equal ~equal:X.equal
- let to_string l =
- Printf.sprintf "[%s]"
- (String.concat ~sep:";"
- (List.map ~f:X.to_string l))
- end
- module IntOption = Option_(Int)
- module StringOption = Option_(String_)
- module StringList = List_(String_)
- let asrt (type a) (module X: TESTABLE with type t = a) e a =
- assert_equal ~cmp:X.equal ~printer:X.to_string e a
- let t name m e a =
- name>::fun _ -> asrt m e a
- let ts m l =
- test_list
- (List.map l ~f:(fun (name, e, a) -> t name m e a))
- let log, t_log =
- let out = ref [] in
- let log x =
- out := x::!out
- in
- let t_log name expected func =
- out := [];
- func ();
- t name (module StringList) expected (List.rev !out)
- in
- log, t_log
- let logf fmt = Printf.ksprintf log fmt
|