I'm trying to get nim code coverage working again in the new nim 1.0 version. It was working several months ago. Now it's reporting coverage on the c code instead of the nim lines. The html output shows 100% coverage on the x.nim.c file when it shouldn't and the standard lib files are not stripped out.
I'm running on a mac following the simple example shown at https://hookrace.net/blog/nim-code-coverage/ and then changing the nim cache path to '~/.cache/nim. This page shows the html output I'm expecting.
Here is the code if you want to try it out:
x.nim file:
var x = 0
if x > 1:
echo "foo"
echo "bar"
ct.sh file:
#!/bin/sh
# Remove old coverage information.
rm -rf *.info html ~/.cache/nim
# Compile t.nim module with coverage instrumentation. Generate x exe.
nim c --debugger:native --passC:--coverage --passL:--coverage x
# Reset the coverage counters.
lcov --base-directory . --directory ~/.cache/nim --zerocounters -q
# Run the instrumented program.
./x
# Read data files and generate x.info file with code coverage data.
lcov --base-directory . --directory ~/.cache/nim -c -o x.info
# Remove nim system libs from x.info coverage.
lcov --remove t.info "*/lib/*" -o x.info
# Generate html reports from the x.info file and put them in the html
# directory.
genhtml -o html x.info
Run ct.sh and open the html index file in your browser:
./ct.sh
Bumping this as it appears coco and lcov are not working on the lastest Nim version. See https://github.com/nim-lang/Nim/issues/8598 .
Is there any solution to generate code coverage report (ideally with lcov) from unit tests ? I know of https://github.com/yglukhov/coverage but it implies to modify the code of the tests.