package ppx_inline_alcotest

  1. Overview
  2. Docs
Inline tests backend for alcotest

Install

Dune Dependency

Authors

Maintainers

Sources

ppx-inline-alcotest-1.0.0.tar.gz
sha256=373e88fcc5d143e7070b8a1008511a58e49b6d1f8c3bf6df7a3fbc8def7debdc
md5=4a89e24597d249ec8d3d91449785295b

doc/src/ppx_inline_alcotest.runner/ppx_inline_alcotest_runner.ml.html

Source file ppx_inline_alcotest_runner.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let test_map = Hashtbl.create 100

let add_test ~path:filename ~test_name fn =
  let test : unit Alcotest.test_case = Alcotest.test_case test_name `Quick fn in
  match Hashtbl.find_opt test_map filename with
  | None -> Hashtbl.add test_map filename [test]
  | Some tests -> Hashtbl.replace test_map filename (test :: tests)


let build_test_suite () = Hashtbl.fold (fun k v acc -> (k,v) :: acc) test_map []

let get_filename () =
  let exec_name = Sys.argv.(0) in
  String.split_on_char '.' exec_name
  |> List.filter (fun v -> not (String.equal "" v))
  |> List.hd


let run () =
  let filename = get_filename () in
  let test_suite = build_test_suite () in
  Alcotest.run filename test_suite
OCaml

Innovation. Community. Security.