aantron / bisect_ppx

Code coverage for OCaml and ReScript
http://aantron.github.io/bisect_ppx/demo/
MIT License
302 stars 60 forks source link

`bisect_ppx` doesn't see the instrumentation clause in my library #408

Closed hirrolot closed 1 year ago

hirrolot commented 1 year ago

I have the following project structure:

.
├── bin
│   ├── dune
│   └── main.ml
├── dune-project
├── lib
│   ├── dune
│   └── pld.ml
├── pld.opam
└── test
    ├── dune
    └── test.ml

Inside lib/dune:

(library
 (public_name pld)
 (preprocess
  (pps ppx_deriving.show ppx_deriving.eq))
 (instrumentation
  (backend bisect_ppx)))

Inside test/dune:

(test
 (name test)
 (libraries pld ounit2))

I expect bisect_ppx to do test coverage of my lib. However, when I execute the following commands:

$ find . -name '*.coverage' | xargs rm -f
$ dune test --instrument-with bisect_ppx --force
$ bisect-ppx-report html

I obtain Error: no *.coverage files found.

What am I doing wrong? I think that bisect_ppx just doesn't see the instrumentation clause inside lib/dune. If I add the same clause in test/dune, it will generate test coverage (but rather uselessly -- for the tests themselves).

hirrolot commented 1 year ago

Well, it turns out that when I actually use functions from lib/ inside the tests, everything works perfectly. It's still, however, very confusing, and I don't know whether it's intended or not. With empty tests, I'd rather expect to see 0% test coverage.

alopezz commented 1 year ago

I think this is due to what's described in #136, #391 (I just encountered a similar issue and was looking for answers, too).

aantron commented 1 year ago

Perhaps the Error: no *.coverage files found message can include some hints as to what the cause can be, and the files not being linked into the project will be one of the hints.

aantron commented 1 year ago

It's difficult for Bisect to, in a general way, know that you might have files that have not been linked into the build of the test suite (what I meant by project above), but Bisect can make an effort to warn users about that in various places.