(originally posted here: https://zig.news/liyu1981/tiny-change-to-kcov-for-better-covering-zig-hjm)
Recently just engaged with Zig, and I really like it. Strongly believe in that "Favor reading code over writing code." So I start to do something with it, and then I start to wonder how to use coverage tools.
Then I have read this wonderful article here
https://zig.news/squeek502/code-coverage-for-zig-1dk1, and learned kcov
as such as amazing tool: fast and easy to use, and it works without any headache.
There is only one thing letting me down, which is that I do not find any instructions in kcov on how to ignore some lines in source code for not covering.
And as Zig has unreachable
and @panic
which should never be covered, so I spend some time wondering in the cpp code base of kcov.
Turns out, it is easier than I image, so I forked kcov and create my own version.
- It can recognise zig’s
unreachable
and@panic
, auto ignore it. - I also added the ability to add
/* no-cover */
in c/cpp source code so that can make kcov ignore some lines too.
The result is quite satisfying to myself, like
this one auto ignoring unreachable
or this one auto ignoring @panic
or this one manual ignoring line with /* no-cover */
The repo is here:
https://github.com/liyu1981/kcov/tree/kcov-zig
Hope it is useful for not just me 🙂