Permalink
Browse files

adding code coverage for the tests (using bisect)

simply run: ocamlbuild coverage/index.html
and then: gnome-open coverage/index.html
  • Loading branch information...
1 parent 8ba79be commit 4f1941e6a19673e5aa15d1f4c091fcc01cbdccf7 @sliquister sliquister committed Jan 16, 2012
Showing with 48 additions and 1 deletion.
  1. +2 −0 README.md
  2. +45 −0 myocamlbuild.ml
  3. +1 −1 src/batParserCo.ml
View
2 README.md
@@ -26,12 +26,14 @@ You will need the following libraries:
* GNU make
* [OUnit][] to build and run the tests (optional)
* [ocaml-benchmark][] to build and run the performance tests (optional)
+* [bisect][] to compute the coverage of the test suite (optional)
[Findlib]: http://projects.camlcity.org/projects/findlib.html/
[OCaml]: http://caml.inria.fr/ocaml/release.en.html
[Camomile]: http://camomile.sourceforge.net/
[OUnit]: http://ounit.forge.ocamlcore.org/
[ocaml-benchmark]: http://ocaml-benchmark.forge.ocamlcore.org/
+[bisect]: http://bisect.x9c.fr/
### Configuration and Installation
View
45 myocamlbuild.ml
@@ -14,6 +14,22 @@ let doc_intro = "build/intro.text"
let mkconf = "build/mkconf.byte"
let pa_llist = "src/syntax/pa_llist/pa_llist.cmo"
+(* removes the trailing newlines in the stdout of s *)
+let run_and_read s =
+ let res = run_and_read s in
+ String.chomp res
+
+let bisect_dir = run_and_read "ocamlfind query bisect"
+let bisect_pp = Pathname.concat bisect_dir "bisect_pp.cmo"
+
+let src_bat_ml =
+ let l = Array.to_list (Pathname.readdir "src") in
+ let l =
+ List.filter (fun filename ->
+ String.is_prefix "bat" filename && String.is_suffix filename ".ml"
+ ) l in
+ List.map (fun filename -> Pathname.concat "src" filename) l
+
let _ = dispatch begin function
| Before_options ->
(* Set up to use ocamlfind *)
@@ -48,6 +64,26 @@ let _ = dispatch begin function
~deps:["META.in"; mkconf]
begin fun env build ->
Cmd(S[A"ocamlrun"; P mkconf; P"META.in"; P"META"])
+ end;
+
+ rule "code coverage"
+ ~prod:"coverage/index.html"
+ ~deps:src_bat_ml
+ begin fun env build ->
+ List.iter (fun filename ->
+ tag_file filename ["with_pa_bisect"; "syntax_camlp4o"; "use_bisect"];
+ ) src_bat_ml;
+ tag_file "testsuite/main.native" ["use_bisect"];
+ tag_file "qtest/test_runner.native" ["use_bisect"];
+ List.iter Outcome.ignore_good (
+ build [["testsuite/main.native"]; ["qtest/test_runner.native"]]
+ );
+ Seq [
+ Cmd(S[Sh"rm -f bisect*.out"]);
+ Cmd(S[A"qtest/test_runner.native"]);
+ Cmd(S[A"testsuite/main.native"]);
+ Cmd(S[Sh"bisect-report -html coverage bisect*.out"]);
+ ]
end
| After_rules ->
@@ -102,6 +138,15 @@ let _ = dispatch begin function
S[A"-ppopt"; P pa_llist];
dep ["ocaml"; "ocamldep"; "with_pa_llist"] [pa_llist];
+ let flags_pa_bisect =
+ S[A"-ppopt"; P"str.cma"; A"-ppopt"; P bisect_pp;
+ A"-ppopt"; A"-disable"; A"-ppopt"; A"b"] in
+ (* bisect screws up polymorphic recursion without -disable b *)
+ flag ["ocaml"; "compile"; "with_pa_bisect"] & flags_pa_bisect;
+ flag ["ocaml"; "ocamldep"; "with_pa_bisect"] & flags_pa_bisect;
+
+ ocaml_lib ~extern:true ~dir:bisect_dir "bisect";
+
ocaml_lib "qtest/test_mods";
ocaml_lib "src/batteries";
ocaml_lib "src/batteriesThread";
View
2 src/batParserCo.ml
@@ -327,5 +327,5 @@ let range a b = satisfy (fun x -> a <= x && x <= b)
let sat f = (satisfy f) >>> return ()
module Infix = struct
- let (<|>), (~?), (>>=), (>>>), (>::), (~*), (~+), (^^) = (<|>), (~?), (>>=), (>>>), (>::), (~*), (~+), (^^)
+ let (<|>), (~?), (>>=), (>>>), (>::), ( ~* ), (~+), (^^) = (<|>), (~?), (>>=), (>>>), (>::), ( ~* ), (~+), (^^)
end

0 comments on commit 4f1941e

Please sign in to comment.