From 803296796b2a3b1073f1edb599eebff78d2b4801 Mon Sep 17 00:00:00 2001 From: Anders Fugmann Date: Wed, 31 Jan 2024 22:17:02 +0100 Subject: [PATCH] Add bisect target to visualize test coverage and test different encoding strategies --- .gitignore | 1 + Makefile | 11 +++++++++-- ocaml-protoc-plugin.opam | 1 + src/ocaml_protoc_plugin/dune | 1 + src/plugin/dune | 1 + test/dune | 4 +++- test/test_lib.ml | 7 +++++++ 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5ced639..c98132e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /_build/ /_opam/ /*.install +_coverage .merlin node_modules lib diff --git a/Makefile b/Makefile index 3913ea2..32c1192 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/ocaml-protoc-plugin.opam b/ocaml-protoc-plugin.opam index 75d1ed1..2e38cb2 100644 --- a/ocaml-protoc-plugin.opam +++ b/ocaml-protoc-plugin.opam @@ -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} ] diff --git a/src/ocaml_protoc_plugin/dune b/src/ocaml_protoc_plugin/dune index a478b6c..cd23605 100644 --- a/src/ocaml_protoc_plugin/dune +++ b/src/ocaml_protoc_plugin/dune @@ -4,4 +4,5 @@ (synopsis "Serialization and deserialization of protobuf types") (inline_tests) (preprocess (pps ppx_expect)) + (instrumentation (backend bisect_ppx)) ) diff --git a/src/plugin/dune b/src/plugin/dune index 5219723..c6ec0a1 100644 --- a/src/plugin/dune +++ b/src/plugin/dune @@ -3,4 +3,5 @@ (public_name protoc-gen-ocaml) (libraries spec) (package ocaml-protoc-plugin) + (instrumentation (backend bisect_ppx)) ) diff --git a/test/dune b/test/dune index 76b2dd6..69a156b 100644 --- a/test/dune +++ b/test/dune @@ -25,7 +25,9 @@ (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)) +) + (rule diff --git a/test/test_lib.ml b/test/test_lib.ml index e535d69..591179f 100644 --- a/test/test_lib.ml +++ b/test/test_lib.ml @@ -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 @@ -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;