How to install LCOV on Windows (in MSYS2)

2015-05-29

LCOV is a graphical front-end for GCC code coverage testing tool gcov.

MSYS2 is a collection of Unix GNU shell utilities for Windows, like the shell, terminal emulator, development tools, and a true package manager pacman.

MSYS2 is a newer fork of Cygwin than more widely known MinGW/MSYS. So MSYS and MSYS2 are two different projects.

This note describes how to install LCOV on Windows (in MSYS2) and generate test coverage reports.

Step 1: Install MSYS2

Follow instructions on http://msys2.github.io/

Step 2: Install LCOV

There is a PKGBUILD file (a package-building recipe) for LCOV on Archlinux. Fortunately, it works in MSYS2 too. To build a package you may need to install curl, perl, tar, and patch first┬╣.

  1. Download LCOV package source:

    curl https://aur.archlinux.org/packages/lc/lcov/lcov.tar.gz | tar zxf -
    cd lcov/
    
  2. Read PKGBUILD first, to make sure it does what you want.

    less PKGBUILD
    

    (q to quit)

  3. Build and install the package

    makepkg -csi
    

    Options are -clean after build, -sync (install) missing dependencies, -i install the package after successful build.

┬╣) To install a package whatever in Archlinux MSYS2, run:

pacman -Su whatever

To search for available packages:

pacman -Ss whatever

Step 3: Use LCOV

Just use LCOV normally.

  1. Build your tests with --coverage and -g (debug) flags using GCC.

  2. Run tests.

  3. Collect coverage data:

     lcov --capture --directory project-dir --output-file coverage.info
    
  4. Generate HTML report:

     genhtml coverage.info --output-directory out