(* -*- tuareg -*- *)

let suffix =
  try
    let major_version = List.hd (String.split_on_char '.' Sys.ocaml_version) in
    if int_of_string major_version < 5 then string_of_int Sys.word_size else "ocaml5"
  with _ -> failwith ("Unknown OCaml version format: " ^ Sys.ocaml_version)

let dune = Printf.sprintf {|

(executable
  (name QCheck_alcotest_test)
  (libraries qcheck-core qcheck-alcotest alcotest))

(rule
  (targets output.txt)
  (deps ./QCheck_alcotest_test.exe)
  (enabled_if (= %%{os_type} "Unix"))
  (action
    (with-accepted-exit-codes
      1
      (setenv
        QCHECK_SEED 1234
        (with-stdout-to
          %%{targets}
          (run ./run_alcotest.sh --color=never))))))

(rule
  (alias runtest)
  (package qcheck-alcotest)
  (enabled_if (= %%{os_type} "Unix"))
  (action (diff output.txt.expected.%s output.txt)))

|} suffix

let () = Jbuild_plugin.V1.send dune
