Code coverage for Nim using LCOV.
- Line & Branch coverage support
- Forwards nim compiler options
- Works out-of-the box with Nim unittests
- API + CLI
- HTML report
Install using Nimble:
nimble install cocoGenerate a code coverage report:
coco --target "tests/**/*.nim" --cov '!tests' --compiler="--hints:off" The flag --target tells Coco to run and compile nim files in the tests/ directory (and subdirectories if any).
The flag --cov is helpful for extracting or removing data from the file *.info. Here we don't want code coverage for our tests, only for our main library coco.
The flag --compiler forwards its value directly to the Nim compiler.
To get the full list of available flags, type in your shell coco -h
By default, Coco will generate a lcov.info file on your project root folder and create a report under coverage/.
To check your report, open the file coverage/index.htmlin your browser:
Install Coverage Gutters.
This nice plugin will map your coverage to your source code right into VScode:
import and use:
import coco
discard coverage(target = "tests/foo.nim", branch = true)
You can find the full documentation here: API Coco
This task has only been tested under MacOSX. Feel free to open a pull request to share your experiments to code coverage Nim projects.
- Support for subdirectories in tests/
- Coveralls.io integration


