Skip to content
This repository
Browse code

adding code coverage for the tests (using bisect)

simply run: ocamlbuild coverage/index.html
and then: gnome-open coverage/index.html
  • Loading branch information...
commit 4f1941e6a19673e5aa15d1f4c091fcc01cbdccf7 1 parent 8ba79be
sliquister sliquister authored

Showing 3 changed files with 48 additions and 1 deletion. Show diff stats Hide diff stats

  1. +2 0  README.md
  2. +45 0 myocamlbuild.ml
  3. +1 1  src/batParserCo.ml
2  README.md
Source Rendered
@@ -26,12 +26,14 @@ You will need the following libraries:
26 26 * GNU make
27 27 * [OUnit][] to build and run the tests (optional)
28 28 * [ocaml-benchmark][] to build and run the performance tests (optional)
  29 +* [bisect][] to compute the coverage of the test suite (optional)
29 30
30 31 [Findlib]: http://projects.camlcity.org/projects/findlib.html/
31 32 [OCaml]: http://caml.inria.fr/ocaml/release.en.html
32 33 [Camomile]: http://camomile.sourceforge.net/
33 34 [OUnit]: http://ounit.forge.ocamlcore.org/
34 35 [ocaml-benchmark]: http://ocaml-benchmark.forge.ocamlcore.org/
  36 +[bisect]: http://bisect.x9c.fr/
35 37
36 38 ### Configuration and Installation
37 39
45 myocamlbuild.ml
@@ -14,6 +14,22 @@ let doc_intro = "build/intro.text"
14 14 let mkconf = "build/mkconf.byte"
15 15 let pa_llist = "src/syntax/pa_llist/pa_llist.cmo"
16 16
  17 +(* removes the trailing newlines in the stdout of s *)
  18 +let run_and_read s =
  19 + let res = run_and_read s in
  20 + String.chomp res
  21 +
  22 +let bisect_dir = run_and_read "ocamlfind query bisect"
  23 +let bisect_pp = Pathname.concat bisect_dir "bisect_pp.cmo"
  24 +
  25 +let src_bat_ml =
  26 + let l = Array.to_list (Pathname.readdir "src") in
  27 + let l =
  28 + List.filter (fun filename ->
  29 + String.is_prefix "bat" filename && String.is_suffix filename ".ml"
  30 + ) l in
  31 + List.map (fun filename -> Pathname.concat "src" filename) l
  32 +
17 33 let _ = dispatch begin function
18 34 | Before_options ->
19 35 (* Set up to use ocamlfind *)
@@ -48,6 +64,26 @@ let _ = dispatch begin function
48 64 ~deps:["META.in"; mkconf]
49 65 begin fun env build ->
50 66 Cmd(S[A"ocamlrun"; P mkconf; P"META.in"; P"META"])
  67 + end;
  68 +
  69 + rule "code coverage"
  70 + ~prod:"coverage/index.html"
  71 + ~deps:src_bat_ml
  72 + begin fun env build ->
  73 + List.iter (fun filename ->
  74 + tag_file filename ["with_pa_bisect"; "syntax_camlp4o"; "use_bisect"];
  75 + ) src_bat_ml;
  76 + tag_file "testsuite/main.native" ["use_bisect"];
  77 + tag_file "qtest/test_runner.native" ["use_bisect"];
  78 + List.iter Outcome.ignore_good (
  79 + build [["testsuite/main.native"]; ["qtest/test_runner.native"]]
  80 + );
  81 + Seq [
  82 + Cmd(S[Sh"rm -f bisect*.out"]);
  83 + Cmd(S[A"qtest/test_runner.native"]);
  84 + Cmd(S[A"testsuite/main.native"]);
  85 + Cmd(S[Sh"bisect-report -html coverage bisect*.out"]);
  86 + ]
51 87 end
52 88
53 89 | After_rules ->
@@ -102,6 +138,15 @@ let _ = dispatch begin function
102 138 S[A"-ppopt"; P pa_llist];
103 139 dep ["ocaml"; "ocamldep"; "with_pa_llist"] [pa_llist];
104 140
  141 + let flags_pa_bisect =
  142 + S[A"-ppopt"; P"str.cma"; A"-ppopt"; P bisect_pp;
  143 + A"-ppopt"; A"-disable"; A"-ppopt"; A"b"] in
  144 + (* bisect screws up polymorphic recursion without -disable b *)
  145 + flag ["ocaml"; "compile"; "with_pa_bisect"] & flags_pa_bisect;
  146 + flag ["ocaml"; "ocamldep"; "with_pa_bisect"] & flags_pa_bisect;
  147 +
  148 + ocaml_lib ~extern:true ~dir:bisect_dir "bisect";
  149 +
105 150 ocaml_lib "qtest/test_mods";
106 151 ocaml_lib "src/batteries";
107 152 ocaml_lib "src/batteriesThread";
2  src/batParserCo.ml
@@ -327,5 +327,5 @@ let range a b = satisfy (fun x -> a <= x && x <= b)
327 327 let sat f = (satisfy f) >>> return ()
328 328
329 329 module Infix = struct
330   - let (<|>), (~?), (>>=), (>>>), (>::), (~*), (~+), (^^) = (<|>), (~?), (>>=), (>>>), (>::), (~*), (~+), (^^)
  330 + let (<|>), (~?), (>>=), (>>>), (>::), ( ~* ), (~+), (^^) = (<|>), (~?), (>>=), (>>>), (>::), ( ~* ), (~+), (^^)
331 331 end

0 comments on commit 4f1941e

Please sign in to comment.
Something went wrong with that request. Please try again.