Module coco

This module is the API behind the binary Coco.

Coco makes line or branch code coverage for Nim a breeze.
  • Depends on LCOV
  • Generates a nice looking HTML report
  • Works with visualization tools like Coverage Gutters on VSCode.

Procs

proc get_cache_folder(filename, nimcache: string; increment = 0): string {...}{.raises: [],
    tags: [].}
proc compile(target = "tests/**/*.nim"; nimcache = "nimcache"; verbose = false;
            options = "") {...}{.raises: [OSError, OSError, Exception, RegexError,
                                 GlobSyntaxError, OSError, Exception, RegexError,
                                 GlobSyntaxError],
                         tags: [ReadDirEffect, RootEffect, ExecIOEffect].}
Compiles Nim files in coverage mode
  • target should be a Glob with a .nim extension
proc reset_coverage(source = "lcov.info"; path = "coverage"; nimcache = "nimcache") {...}{.
    raises: [], tags: [ExecIOEffect].}
Removes everything generated by a past code coverage generation:
  • Nimcache folder
  • .info
  • Code coverage report folder
proc trace(target: string) {...}{.raises: [OSError, OSError, Exception, RegexError,
                                  GlobSyntaxError, OSError, Exception, RegexError,
                                  GlobSyntaxError],
                          tags: [ReadDirEffect, RootEffect, ExecIOEffect].}
Runs the compiled Nim files to produce coverage informations.
  • target should be a Glob with a .nim extension.
proc cleanup_report(fileinfo = "lcov.info"; cov: string; verbose = false; branch = false) {...}{.raises: [
    ValueError, OSError, OSError, Exception, RegexError, GlobSyntaxError, OSError,
    Exception, RegexError, GlobSyntaxError, OSError, Exception, OSError, Exception,
    RegexError, GlobSyntaxError], tags: [ExecIOEffect, ReadDirEffect, RootEffect].}
Keeps only relevant coverage informations
Without any cleanup, your code coverage report will include standard libraries, tests and so on.
proc genhtml(source = "lcov.info"; path = "coverage"; verbose = false; branch = false) {...}{.
    raises: [], tags: [ExecIOEffect].}
Generates the HTML code coverage report from a .info file generated by LCOV
proc coverage(target = "tests/**/*.nim"; cov = "!tests"; verbose = false; branch = false;
             nimcache = "nimcache"; report_source = "lcov.info";
             report_path = "coverage"; compiler = ""): int {...}{.
    raises: [OSError, Exception, RegexError, GlobSyntaxError, ValueError],
    tags: [ExecIOEffect, ReadDirEffect, RootEffect].}

Code coverage for Nim:
  1. Clean up past reports
  2. Compile nim files in coverage mode
  3. Run the the executables
  4. Capture, produce and cleanup LCOV .info file
  5. Generate the HTML report