diff --git a/.gitignore b/.gitignore index ec464113b6..87b0876181 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ setup.log # Backup of opam lock file hazel.opam.locked.old + +# Code coverage +_coverage/ diff --git a/Makefile b/Makefile index 516016ddf8..5eef59a1d4 100644 --- a/Makefile +++ b/Makefile @@ -66,5 +66,13 @@ test: watch-test: dune build @ocaml-index @fmt @runtest --auto-promote --watch +coverage: + dune build @src/fmt @test/fmt --auto-promote src test --profile dev + dune runtest --instrument-with bisect_ppx --force + bisect-ppx-report summary + +generate-coverage-html: + bisect-ppx-report html + clean: dune clean diff --git a/README.md b/README.md index a15bdd424e..15caf27308 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,9 @@ You can run all of the unit tests located in `test` by running `make test`. Unit tests are written using the [Alcotest framework](https://github.com/mirage/alcotest). +#### Coverage +Code coverage is provided by [bisect_ppx](https://github.com/aantron/bisect_ppx). To collect coverage statistics from tests run `make coverage`. After coverage statistics are generated, running `make generate-coverage-html` will generate a local webpage at `_coverage/index.html` that can be viewed to see line coverage per module. + ### Continuous Integration When you push your branch to the main `hazelgrove/hazel` repository, we diff --git a/dune-project b/dune-project index 1194593485..4dd3442bc4 100644 --- a/dune-project +++ b/dune-project @@ -26,9 +26,11 @@ (menhir (>= 2.0)) yojson - reason + (reason (>= 3.12.0)) ppx_yojson_conv_lib ppx_yojson_conv + incr_dom + bisect_ppx (omd (>= 2.0.0~alpha4)) ezjs_idb bonsai diff --git a/hazel.opam b/hazel.opam index e78b188325..09ee887ab3 100644 --- a/hazel.opam +++ b/hazel.opam @@ -11,9 +11,10 @@ depends: [ "ocaml" {>= "5.2.0"} "menhir" {>= "2.0"} "yojson" - "reason" + "reason" {>= "3.12.0"} "ppx_yojson_conv_lib" "ppx_yojson_conv" + "bisect_ppx" "omd" {>= "2.0.0~alpha4"} "ezjs_idb" "bonsai" diff --git a/hazel.opam.locked b/hazel.opam.locked index b2cfce2cea..856b83ad33 100644 --- a/hazel.opam.locked +++ b/hazel.opam.locked @@ -39,6 +39,7 @@ depends: [ "bigstringaf" {= "0.10.0"} "bin_prot" {= "v0.16.0"} "bonsai" {= "v0.16.0"} + "bisect_ppx" {= "2.8.3"} "camlp-streams" {= "5.0.1"} "chrome-trace" {= "3.16.0"} "cmdliner" {= "1.3.0"} diff --git a/src/haz3lcore/dune b/src/haz3lcore/dune index 77e2ca3fe1..a0d9770816 100644 --- a/src/haz3lcore/dune +++ b/src/haz3lcore/dune @@ -4,6 +4,8 @@ (name haz3lcore) (libraries util sexplib unionFind uuidm virtual_dom yojson core) (js_of_ocaml) + (instrumentation + (backend bisect_ppx)) (preprocess (pps ppx_yojson_conv diff --git a/src/haz3lweb/dune b/src/haz3lweb/dune index d3e42ec636..772e6b9862 100644 --- a/src/haz3lweb/dune +++ b/src/haz3lweb/dune @@ -8,6 +8,8 @@ (library (name workerServer) (modules WorkerServer) + (instrumentation + (backend bisect_ppx)) (libraries bonsai bonsai.web @@ -29,6 +31,8 @@ (library (name haz3lweb) + (instrumentation + (backend bisect_ppx)) (modules (:standard \ Main) \ diff --git a/src/pretty/dune b/src/pretty/dune index 868d03defc..c131965aff 100644 --- a/src/pretty/dune +++ b/src/pretty/dune @@ -3,6 +3,8 @@ (library (name pretty) (libraries util sexplib) + (instrumentation + (backend bisect_ppx)) (preprocess (pps ppx_let ppx_sexp_conv))) diff --git a/src/util/dune b/src/util/dune index a3494db579..9da34a5594 100644 --- a/src/util/dune +++ b/src/util/dune @@ -2,6 +2,8 @@ (name util) (libraries re base ptmap bonsai bonsai.web virtual_dom yojson) (js_of_ocaml) + (instrumentation + (backend bisect_ppx)) (preprocess (pps ppx_yojson_conv diff --git a/test/dune b/test/dune index 832c9689f2..3b9dc8bb2e 100644 --- a/test/dune +++ b/test/dune @@ -2,7 +2,7 @@ (test (name haz3ltest) - (libraries haz3lcore alcotest junit junit_alcotest) + (libraries haz3lcore alcotest junit junit_alcotest bisect_ppx.runtime) (modes js) (preprocess - (pps js_of_ocaml-ppx))) + (pps js_of_ocaml-ppx ppx_deriving.show))) diff --git a/test/haz3ltest.re b/test/haz3ltest.re index 03cebe774c..8e4a838b0a 100644 --- a/test/haz3ltest.re +++ b/test/haz3ltest.re @@ -13,3 +13,4 @@ let (suite, _) = ], ); Junit.to_file(Junit.make([suite]), "junit_tests.xml"); +Bisect.Runtime.write_coverage_data();