M src/oth/oth.ml +15 -14
@@ 1,4 1,4 @@
-open Core.Std
+module List = ListLabels
(*
* This isn't here actually but will be used to propogate
@@ 22,7 22,7 @@ end
*)
let test_success = ref true
-let dev_null = Fn.const ()
+let dev_null = CCFun.const ()
let run_tests state test =
test state
@@ 33,47 33,48 @@ let serial tests state =
let parallel = serial
let time_call f =
- let start = Time.now () in
+ let start = Sys.time () in
let res = f () in
- let stop = Time.now () in
- let sec = Core.Span.to_sec (Time.diff stop start) in
+ let stop = Sys.time () in
+ let sec = stop -. start in
(sec, res)
let test ?(desc = "") ~name f state =
- let t = fun () -> Result.try_with (fun () -> f state) in
+ let t = fun () -> CCResult.guard (fun () -> f state) in
match time_call t with
| (time, Ok ()) -> begin
- state.State.log (sprintf "Test: %s\t\tPASSED (%0.2f sec)\n" name time);
+ state.State.log (Printf.sprintf "Test: %s\t\tPASSED (%0.2f sec)\n" name time);
()
end
| (time, Error exn) -> begin
state.State.log
- (sprintf "Test: %s\t\tFAILED (%0.2f sec)\nDescription:\n%s\nExn:\n%s\n"
+ (Printf.sprintf "Test: %s\t\tFAILED (%0.2f sec)\nDescription:\n%s\nExn:\n%s\n"
name
time
desc
- (Exn.to_string exn));
+ (Printexc.to_string exn));
test_success := false;
()
end
let name ~name tst state =
let t = fun () -> run_tests state tst in
- let (time, ()) = time_call t in
+ let (time, ()) = time_call t in
state.State.log
- (sprintf "Test: %s\t\tELAPSED (%0.2f sec)\n" name time);
+ (Printf.sprintf "Test: %s\t\tELAPSED (%0.2f sec)\n" name time);
()
let result_test rtest state =
let res = rtest state in
- assert (Result.is_ok res);
- ()
+ match res with
+ | Ok _ -> ()
+ | Error _ -> assert false
let test_with_revops ?desc ~name ~revops tst =
test
?desc
~name
- (fun state -> Revops.run_in_context revops (Fn.flip tst state))
+ (fun state -> Revops.run_in_context revops (CCFun.flip tst state))
let exit_of_success () =
match !test_success with
M src/oth/oth.mli +2 -4
@@ 1,5 1,3 @@
-open Core.Std
-
(** Internal state of the test, explicitly passed around with some
combinators. *)
module State : sig
@@ 28,7 26,7 @@ val serial : Test.t list -> Test.t
val loop : int -> Test.t -> Test.t
(** Run a test and timeout if it does not finish in a given amount of time *)
-val timeout : Core.Span.t -> Test.t -> Test.t
+val timeout : Duration.t -> Test.t -> Test.t
(** Turn a function into a test *)
val test : ?desc:string -> name:string -> (State.t -> unit) -> Test.t
@@ 40,7 38,7 @@ val name : name:string -> Test.t -> Test
(** Turn a test that returns a result into one that returns a unit. This
asserts that the result is on the 'Ok' path. *)
val result_test :
- (State.t -> (unit, 'err) Result.t) ->
+ (State.t -> (unit, 'err) result) ->
State.t ->
unit