diff --git a/qCheck.ml b/qCheck.ml index e4493dee..f8993fa0 100644 --- a/qCheck.ml +++ b/qCheck.ml @@ -39,6 +39,8 @@ module Arbitrary = struct then 0 else start + Random.State.int st n + let (--) start stop = int_range ~start ~stop + let small_int = int 100 let bool = Random.State.bool @@ -254,20 +256,20 @@ let run ?(out=stdout) ?(rand=Random.State.make_self_init()) (Test test) = Printf.fprintf out "testing property %s...\n" test.name; match check ~rand ~n:test.n test.gen test.prop with | Ok (n, prefail) -> - Printf.fprintf out "passed %d tests (%d preconditions failed)\n" n prefail; + Printf.fprintf out " [✔] passed %d tests (%d preconditions failed)\n" n prefail; true | Failed l -> begin match test.pp with - | None -> Printf.fprintf out "%d failures\n" (List.length l) + | None -> Printf.fprintf out " [×] %d failures\n" (List.length l) | Some pp -> - Printf.fprintf out "%d failures:\n" (List.length l); + Printf.fprintf out " [×] %d failures:\n" (List.length l); List.iter (fun x -> Printf.fprintf out " %s\n" (pp x)) l end; false | Error e -> - Printf.fprintf out "error: %s\n" (Printexc.to_string e); + Printf.fprintf out " [×] error: %s\n" (Printexc.to_string e); false type suite = test list @@ -275,10 +277,12 @@ type suite = test list let flatten = List.flatten let run_tests ?(out=stdout) ?(rand=Random.State.make_self_init()) l = - let res = ref true in + let start = Unix.gettimeofday () in + let failed = ref 0 in Printf.fprintf out "check %d properties...\n" (List.length l); - List.iter (fun test -> if not (run ~out ~rand test) then res := false) l; - if !res - then Printf.fprintf out "Success!\n" - else Printf.fprintf out "Failure.\n"; - !res + List.iter (fun test -> if not (run ~out ~rand test) then incr failed) l; + Printf.fprintf out "tests run in %.2fs\n" (Unix.gettimeofday() -. start); + if !failed = 0 + then Printf.fprintf out "[✔] Success!\n" + else Printf.fprintf out "[×] Failure (%d tests failed).\n" !failed; + !failed = 0