Skip to content

Commit

Permalink
Add bisect target to visualize test coverage and test different encod…
Browse files Browse the repository at this point in the history
…ing strategies
  • Loading branch information
andersfugmann committed Jan 31, 2024
1 parent ada5af4 commit 7f761cd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/_build/
/_opam/
/*.install
_coverage
.merlin
node_modules
lib
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ clean: ## Clean
@dune clean

.PHONY: test
test: build
test: ## Run tests
@dune runtest --force
@dune runtest

.PHONY: bisect
bisect: ## Run tests in bisect mode
@rm -fr _coverage
@find . -name '*.coverage' | xargs -r rm -f
@dune runtest --instrument-with bisect_ppx --force
bisect-ppx-report html
open _coverage/index.html

.PHONY: install
install: build ## Install
Expand Down
1 change: 1 addition & 0 deletions ocaml-protoc-plugin.opam
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ depends: [
"ppx_expect" {with-test}
"ppx_inline_test" {with-test}
"ppx_deriving" {with-test}
"bisect_ppx" {with-test}
"conf-pkg-config" {build}
]

Expand Down
1 change: 1 addition & 0 deletions src/ocaml_protoc_plugin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
(synopsis "Serialization and deserialization of protobuf types")
(inline_tests)
(preprocess (pps ppx_expect))
(instrumentation (backend bisect_ppx))
)
5 changes: 4 additions & 1 deletion test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
(inline_tests)
(modules :standard \ proto3_optional_test_opt)
(preprocess
(pps ppx_expect ppx_deriving.show ppx_deriving.eq)))
(pps ppx_expect ppx_deriving.show ppx_deriving.eq))
(instrumentation (backend bisect_ppx))
)



(rule
Expand Down
7 changes: 7 additions & 0 deletions test/test_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ let test_encode (type t) ?dump ?(protoc=true) ?protoc_args (module M : T with ty
| _ -> ()
in
let data = M.to_proto expect |> Writer.contents in
let data_speed = M.to_proto' (Writer.init ~mode:Speed ()) expect |> Writer.contents in
let data_space = M.to_proto' (Writer.init ~mode:Space ()) expect |> Writer.contents in
let data_balanced = M.to_proto' (Writer.init ~mode:Balanced ()) expect |> Writer.contents in

let () =
match dump with
Expand All @@ -100,6 +103,10 @@ let test_encode (type t) ?dump ?(protoc=true) ?protoc_args (module M : T with ty
| true -> dump_protoc ?protoc_args (M.name' ()) data
| false -> ()
in

test_decode (module M) Test_runtime.Standard expect data_space;
test_decode (module M) Test_runtime.Standard expect data_speed;
test_decode (module M) Test_runtime.Standard expect data_balanced;
test_decode (module M) Test_runtime.Standard expect data;
test_decode (module M) Test_runtime.Fast expect data;
test_decode (module M) Test_runtime.Full expect data;
Expand Down

0 comments on commit 7f761cd

Please sign in to comment.