Code Coverage Reports
=====================

When writing a test suite for a program or library, it is desirable to know what part of the code is covered by the test suite.  The (system vm coverage) module provides tools to gather code coverage data and to present them, as detailed below.

 -- Scheme Procedure: with-code-coverage thunk
     Run THUNK, a zero-argument procedure, while instrumenting Guile's virtual machine to collect code coverage data.  Return code coverage data and the values returned by THUNK.

 -- Scheme Procedure: coverage-data? obj
     Return #t if OBJ is a coverage data object as returned by with-code-coverage.

 -- Scheme Procedure: coverage-data->lcov data port #:key modules
     Traverse code coverage information DATA, as obtained with with-code-coverage, and write coverage information to port in the .info format used by LCOV (http://ltp.sourceforge.net/coverage/lcov.php).  The report will include all of MODULES (or, by default, all the currently loaded modules) even if their code was not executed.

     The generated data can be fed to LCOV's genhtml command to produce an HTML report, which aids coverage data visualization.

Here's an example use:

     (use-modules (system vm coverage)
                  (system vm vm))

     (call-with-values (lambda ()
                         (with-code-coverage
                           (lambda ()
                             (do-something-tricky))))
       (lambda (data result)
         (let ((port (open-output-file "lcov.info")))
           (coverage-data->lcov data port)
           (close file))))

In addition, the module provides low-level procedures that would make it possible to write other user interfaces to the coverage data.

 -- Scheme Procedures: instrumented-source-files data
     Return the list of ``instrumented'' source files, i.e., source files whose code was loaded at the time DATA was collected.

 -- Scheme Procedures: line-execution-counts data file
     Return a list of line number/execution count pairs for FILE, or #f if FILE is not among the files covered by DATA.  This includes lines with zero count.

 -- Scheme Procedures: instrumented/executed-lines data file
     Return the number of instrumented and the number of executed source lines in FILE according to DATA.

 -- Scheme Procedures: procedure-execution-count data proc
     Return the number of times PROC's code was executed, according to DATA, or #f if PROC was not executed.  When PROC is a closure, the number of times its code was executed is returned, not the number of times this code associated with this particular closure was executed.