File tree Expand file tree Collapse file tree 4 files changed +16
-12
lines changed Expand file tree Collapse file tree 4 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -44,4 +44,7 @@ let%test_module _ = (module struct
4444 let % test _ = (group ~break: (fun _ _ -> false ) mis) = single_letters
4545 let % test _ = (groupi ~break: (fun i _ _ -> i mod 3 = 0 ) mis) = every_three
4646
47+
48+ let % test " slow, but takes no cpu time" = ignore (Unix. nanosleep 0.25 : float ); true
49+
4750end )
Original file line number Diff line number Diff line change @@ -12,8 +12,9 @@ build: [
1212depends: [
1313 "ocaml" {>= "4.04.2"}
1414 "base"
15- "dune" {>= "2.0.0"}
16- "ppxlib" {>= "0.11.0"}
15+ "time_now"
16+ "dune" {>= "2.0.0"}
17+ "ppxlib" {>= "0.11.0"}
1718]
1819synopsis: "Syntax extension for writing in-line tests in ocaml code"
1920description: "
Original file line number Diff line number Diff line change 11(library (name ppx_inline_test_lib) (public_name ppx_inline_test.runtime-lib)
2- (libraries base inline_test_config) (preprocess no_preprocessing))
2+ (libraries base inline_test_config time_now ) (preprocess no_preprocessing))
Original file line number Diff line number Diff line change @@ -337,16 +337,16 @@ let testing =
337337 then `Testing `Am_child_of_test_runner
338338 else `Not_testing )
339339
340+ let wall_time_clock_ns () =
341+ Time_now. nanoseconds_since_unix_epoch ()
342+
343+
340344let time_without_resetting_random_seeds f =
341- let before_sec = Sys. time () in
342- let res =
343- try f ()
344- with e ->
345- time_sec := Sys. time () -. before_sec;
346- raise e
347- in
348- time_sec := Sys. time () -. before_sec;
349- res
345+ let before_ns = wall_time_clock_ns () in
346+ Base.Exn. protect ~finally: (fun[@ inline] () ->
347+ time_sec := Base.Int63. (wall_time_clock_ns () - before_ns |> to_float) /. 1e9 )
348+ ~f
349+
350350
351351let saved_caml_random_state = lazy (Caml.Random.State. make [| 100 ; 200 ; 300 |])
352352let saved_base_random_state = lazy (Base.Random.State. make [| 111 ; 222 ; 333 |])
You can’t perform that action at this time.
0 commit comments