CoverMonkey icon indicating copy to clipboard operation
CoverMonkey copied to clipboard

Code coverage analysis for SpiderMonkey

CoverMonkey is a code-coverage tool for the SpiderMonkey JavaScript interpreter from Mozilla.

Requirements

  • A recent (2011-11-11 or later) debug build of SpiderMonkey. To obtain a debug build, follow the "Advanced Build" directions here:

    https://developer.mozilla.org/En/SpiderMonkey/Build_Documentation

  • Node version 0.5 or later. Get it from http://nodejs.org if you don't already have it installed

Building CoverMonkey

To build CoverMonkey, type:

 make

This just assembles a CoverMonkey node script from the files in src/ The repo includes a pre-assembed version of the script, so you don't have to build CoverMonkey unless you edit the source files.

Running CoverMonkey

To use CoverMonkey, run your code in your debug build of SpiderMonkey with the -D option set, and pipe the output (-D generates a lot of output) to CoverMonkey.

For example:

js -D -f my_library.js -f my_tests.js | CoverMonkey -b 

Details

Usage: CoverMonkey [options]

  CoverMonkey reads the output generated by SpiderMonkey's -D option
  (supported by debug builds of SpiderMonkey only) and analyzes it to
  detect dead code and report code coverage.

  CoverMonkey reads -D data from stdin by default. Use the -d option
  to make it read from a file instead.

  CoverMonkey writes basic code coverage statistics to stdout.
  Use -q, -p, -c and -l to modify the information displayed.

  CoverMonkey can generate an HTML file that annotates and colors your 
  source code to highlight uncovered and dead code and indicate how
  many times each line executed.  Use the -h, -a, and -b options to 
  control HTML generation.

  By default, CoverMonkey will output coverage information for all 
  source files that were run. Use one or more -t options to specify
  which files CoverMonkey should analyze.

Options:

  -d <file> Read -D data from the specified file instead of stdin

  -t <file> Analyze coverage for the specified target file.
            Multiple -t options are allowed.

  -q        Quiet: don't display any output to stdout

  -p        Percent: only display coverage percentage

  -c        Display the coverage statistics in compact tabular form

  -l        List the line numbers of all uncovered lines

  -h <file> Output annotated source code, in HTML format, to the 
            specified file.

  -a        Include assembly code for each line in the HTML file.
            This may be useful for understanding partially-covered
            lines.

  -b        Automatically launch a browser window to display the
            HTML. If no -h option, writes HTML to a temporary file.
            This option may only work on MacOS.

  --atlines Honor //@line comments in the source
            This option is probably not generally useful

  -v        Display the CoverMonkey version number and exit

  --help    Display this message and exit