How it works
Monkey C has no hooks for coverage, so rafiki changes a copy of the source
instead. The steps are the same whether you run rafiki coverage test or each
step yourself.
Instrument
rafiki coverage instrument copies every source file of the project into
bin/coverage and adds a call at the start of each function, like
AutoGeneratedCov.hit(3). Apart from those calls the copies are identical to
the originals. It also writes:
AutoGeneratedCov.mc, which prints a line likeCOVHIT 3the first time each function runs.coverage-manifest.tsv, which maps each number back to its file and function.coverage.jungle, a copy of yourmonkey.jungleadjusted to build the copies. It points at your realmanifest.xmland adds the output directory to the source paths.
The project root is the nearest directory with a manifest.xml, so the command
works from anywhere in the project.
Build and run
Building coverage.jungle with monkeyc --unit-test and running the result
with monkeydo -t runs your tests as usual, with a COVHIT line printed for
every function that runs.
Report
rafiki coverage report reads that output and the manifest, and prints the
coverage per file. Lines that aren’t a COVHIT, and repeated hits for the same
function, are ignored.
Limitations
- Coverage is per function, not per line or branch.
- Resource paths in the jungle file are copied as they are, so a project with
relative
resourcePathentries needs to adjust them by hand.