struct
exception Tests_failed
let max_failures =
try Sys.getenv "MAX_FAILURES" |> int_of_string with _ -> 2_000_000
let failed_tests = ref []
let fail s =
failed_tests := s :: !failed_tests;
if List.length !failed_tests > max_failures then (
List.iter !failed_tests ~f:(fun t ->
eprintf "Failed test: %S\n%!" t
);
raise Tests_failed
) else ()
let new_tmp_dir () =
let db_file = Filename.temp_file "trakeva_tmp_test" ".d" in
Sys.command (sprintf "rm -rf %s" db_file) |> ignore;
Sys.command (sprintf "mkdir -p %s" db_file) |> ignore;
db_file
let run_monad name f =
Lwt_main.run (f ())
|> function
| `Ok () -> ()
| `Error (`Database e) ->
ksprintf fail "%S ends with error: %s" name
(Trakeva.Error.to_string e)
let check names c =
if c then ()
else ksprintf fail "test.assert failed: %s" (String.concat ~sep:" → " names)
let now () = Unix.gettimeofday ()
end