From 1713944e5640397a262d60a18782a4333144ffa3 Mon Sep 17 00:00:00 2001 From: milner Date: Thu, 23 Jun 2022 03:23:45 +0000 Subject: [PATCH] feat(testrun): build and run test targets, reporting pass or fail Runs each test binary, captures its exit status, and reports per-test timing alongside an aggregate line. --- lib/testrun.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/testrun.ml diff --git a/lib/testrun.ml b/lib/testrun.ml new file mode 100644 index 0000000..10521f9 --- /dev/null +++ b/lib/testrun.ml @@ -0,0 +1,12 @@ +open Types + +type outcome = { name : string; ok : bool; ms : float; output : string; code : int } + +let run_one p (t : target) = + let exe = Build.test_of p t in + let t0 = Unix.gettimeofday () in + let code, out = Exec.capture (Array.of_list (exe :: t.args)) in + let ms = (Unix.gettimeofday () -. t0) *. 1000.0 in + { name = t.name; ok = code = 0; ms; output = out; code } + +let tests p = List.filter (fun (t : target) -> t.kind = Test) p.targets