Coverage

Description

Measures the coverage of the unit tests with kcov. FPC does not emit the .gcno and .gcda files that gcov and lcov read, but kcov needs no instrumentation: it reads the DWARF line info of the test executable and sets a breakpoint on each line, so any FPC executable with debug info works.

Example:

pasc coverage

Like pasc test, the command looks for the test project in the current folder or in a tests subfolder. Then it:

Coverage apps/cmd 94.00% (47/50 lines)
          89.66%   26/29  src/commands/Command.Count.pas
         100.00%   21/21  src/commands/Command.Greet.pas
  Report coverage/cmd/index.html

At the root of a workspace it covers every member that has a tests folder, shows the total and merges the reports of the members in coverage/index.html.

Units that no test uses

kcov only sees the units linked into the test executable. A unit that no test uses, directly or indirectly, does not appear in its report, instead of appearing with 0%, which would make the percentage look better than it is. The command lists those units, the ones with code, so the gap is visible:

Not counted src/features/health/Health.Routes.pas (no test uses it)

Units with only declarations, like types and constants, have no line for kcov and are not listed.

Options

The exit code is 1 when the build fails, when the tests could not run or any of them failed, and when the coverage is below –min.

Installing kcov

kcov runs on Linux and macOS, not on Windows. When it is not in the PATH, the command shows how to install it:

Ubuntu 24.04 has no kcov package; it can be built from the sources, as the kcov repository explains.

Next Deps Command


Generated by PasDoc 1.0.4.