Nim: tool for code coverage? lcov + `--passC:--coverage --passL:--coverage` doesn't work

Created on 10 Aug 2018  路  6Comments  路  Source: nim-lang/Nim

the only thing I could find was https://hookrace.net/blog/nim-code-coverage/
however instructions didn't work: /cc @def-
after lcov --base-directory . --directory . -c -o x.info, x.info ends up empty
really would love to be able to reproduce these results @def- had here(https://hookrace.net/public/coverage-minimal/cov/x.nim.gcov.html)

Test suite Tools

Most helpful comment

can we re-open? a working coverage tool is important to have (alongside debugging, profiling tools)

  • unfortunately that project seems to have hit a wall, see blocker issue here https://github.com/samuelroy/coco/issues/13 ; some support is needed in Nim repo
  • I have a concrete idea how to address this, and may work on it when I have cycles or help with whoever wants to tackle this:

    • instrument code (analog to how nimprof does it but simpler)

    • doesn't have the issues of nimprof that I mentioned here https://github.com/nim-lang/Nim/issues/10121 since those were accuracy related; here we just care about hit/no-hit (or, as an extension, number of hits for a line of code)

I'm almost sure this will work and not be too complex to implement

All 6 comments

You don't need a tool in Nim to get coverage report. I have lcov.info coverage file generated and coverage displayed with VSCode plugin https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters.

I am using slightly modified version of https://github.com/yglukhov/coverage module.
Really happy with the way it works.

from my understanding, that library requires heavily modifying source code of project for which I want code coverage:

Add "import coverage" and the top of your sources and add "{.cov.}" to every proc.

hardly seems practical; how long would that manual task take for a project like nim itself?

instead, it should be automatic, and enabled by compiler via a flag nim -cov=coverage_options foo.nim
(in much same way as compiler flags are used to insert debug info, line info, etc)

@timotheecour I made a working version of HookRace code coverage version through a Nimble task. It's automated and based on the unit tests in the folder tests/.

You can check it out here: https://github.com/samuelroy/nim-coverage. Let me know if it works for you.

thanks! will comment directly in your repo

Well I consider this question solved then.

can we re-open? a working coverage tool is important to have (alongside debugging, profiling tools)

  • unfortunately that project seems to have hit a wall, see blocker issue here https://github.com/samuelroy/coco/issues/13 ; some support is needed in Nim repo
  • I have a concrete idea how to address this, and may work on it when I have cycles or help with whoever wants to tackle this:

    • instrument code (analog to how nimprof does it but simpler)

    • doesn't have the issues of nimprof that I mentioned here https://github.com/nim-lang/Nim/issues/10121 since those were accuracy related; here we just care about hit/no-hit (or, as an extension, number of hits for a line of code)

I'm almost sure this will work and not be too complex to implement

Was this page helpful?
0 / 5 - 0 ratings