I’m trying to use alcotest to test some code with the following types and test function. However, unless I use the "--verbose"
flag in argv
when calling the Alcotest run
function, I get no output, even if there are lots of test failures. Using the "--verbose"
flag everything displays fine.
type test = { citation : string option
; caption : string option
; expected : Sexp.t option
; program : string} [@@deriving sexp]
type suite = { title : string
; reference : string option
; tests : test list } [@@deriving sexp]
(** Apply functions to the test programs in a suite *)
let test (s:suite) ~f =
let open Alcotest in
let sexp = testable Sexp.pp Sexp.equal in
let test_set = List.mapi s.tests ~f:(fun i test ->
let name = match test.caption with Some s -> s | None -> Int.to_string i in
let exp = match test.expected with Some s -> s | None -> Sexp.Atom "" in
let fn = fun () -> (check sexp) name exp (f test.program) in
(name, `Quick, fn)
) in
let argv = Array.of_list ["--verbose"] in
run s.title ~argv [("Suite", test_set)]
I wonder if it’s related to how I’m calling test
, using Command
from a separate main.ml
file, where Model
is the module containing the bulk of the project code:
let test =
Command.basic_spec
~summary:"Run the test cases from the given file"
Command.Spec.(
empty
+> anon ("filename" %: file)
++ common )
( fun filename debug verbose () ->
let open Test in
let suite = from_filename filename in
let runner = (fun s -> Model.of_string s |> Model.to_sexp ) in
test ~f:runner suite )