Skip to content

Commit 07f611d

Browse files
committed
v0.14-preview.122.21+09
1 parent 4d16411 commit 07f611d

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

example/example.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
4750
end)

ppx_inline_test.opam

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ build: [
1212
depends: [
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
]
1819
synopsis: "Syntax extension for writing in-line tests in ocaml code"
1920
description: "

runtime-lib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
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))

runtime-lib/runtime.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff 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+
340344
let 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

351351
let saved_caml_random_state = lazy (Caml.Random.State.make [| 100; 200; 300 |])
352352
let saved_base_random_state = lazy (Base.Random.State.make [| 111; 222; 333 |])

0 commit comments

Comments
 (0)