[Ericsson Utvecklings AB]

cover

MODULE

cover

MODULE SUMMARY

A Coverage Analysis Tool for Erlang

DESCRIPTION

The module cover provides a set of functions for coverage analysis of Erlang programs, counting how many times each executable line of code is executed when a program is run.
An executable line contains an Erlang expression such as a matching or a function call. A blank line or a line containing a comment, function head or pattern in a case- or receive statement is not executable.

Coverage analysis can be used to verify test cases, making sure all relevant code is covered, and may also be helpful when looking for bottlenecks in the code.

Before any analysis can take place, the involved modules must be Cover compiled. This means that some extra information is added to the module before it is compiled into a binary which then is loaded. The source file of the module is not affected and no .beam file is created.

Each time a function in a Cover compiled module is called, information about the call is added to an internal database of Cover. The coverage analysis is performed by examining the contents of the Cover database. The output Answer is determined by two parameters, Level and Analysis.

EXPORTS

start() -> {ok,Pid} | {error,Reason}

Types:

Pid = pid()
Reason = {already_started,Pid}

Starts the Cover server which owns the Cover internal database. This function is called automatically by the other functions in the module.

compile(ModFile) -> Result
compile(ModFile, Options) -> Result
compile_module(ModFile) -> Result
compile_module(ModFile, Options) -> Result

Types:

ModFile = Module | File
 Module = atom()
 File = string()
Options = [Option]
 Option = {i,Dir} | {d,Macro} | {d,Macro,Value}

See compile:file/2.
Result = {ok,Module} | {error,File}

Compiles a module for Cover analysis. The module is given by its module name Module or by its file name File. The .erl extension may be omitted. If the module is located in another directory, the path has to be specified.

Options is a list of compiler options which defaults to []. Only options defining include file directories and macros are passed to compile:file/2, everything else is ignored.

If the module is successfully Cover compiled, the function returns {ok,Module}. Otherwise the function returns {error,File}. Errors and warnings are printed as they occur.

Note that the internal database is (re-)initiated during the compilation, meaning any previously collected coverage data for the module will be lost.

compile_directory() -> [Result] | {error,Reason}
compile_directory(Dir) -> [Result] | {error,Reason}
compile_directory(Dir, Options) -> [Result] | {error,Reason}

Types:

Dir = string()
Options = [Option]

See compile_module/1,2
Result = {ok,Module} | {error,File}
See compile_module/1,2
Reason = eacces | enoent

Compiles all modules (.erl files) in a directory Dir for Cover analysis the same way as compile_module/1,2 and returns a list with the return values.

Dir defaults to the current working directory.

The function returns {error,eacces} if the directory is not readable or {error,enoent} if the directory does not exist.

analyse(Module) -> {ok,Answer} | {error,Error}
analyse(Module, Analysis) -> {ok,Answer} | {error,Error}
analyse(Module, Level) -> {ok,Answer} | {error,Error}
analyse(Module, Analysis, Level) -> {ok,Answer} | {error,Error}

Types:

Module = atom()
Analysis = coverage | calls
Level = line | clause | function | module
Answer = {Module,Value} | [{Item,Value}]
 Item = Line | Clause | Function
  Line = {M,N}
  Clause = {M,F,A,C}
  Function = {M,F,A}
   M = F = atom()
   N = A = C = integer()
 Value = {Cov,NotCov} | Calls
  Cov = NotCov = Calls = integer()
Error = {not_cover_compiled,Module}

Performs analysis of a Cover compiled module Module, as specified by Analysis and Level (see above), by examining the contents of the internal database.

Analysis defaults to coverage and Level defaults to function.

If Module is not Cover compiled, the function returns {error,{not_cover_compiled,Module}}.

analyse_to_file(Module) ->
analyse_to_file(Module, OutFile) -> {ok,OutFile} | {error,Error}

Types:

Module = atom()
OutFile = string()
Error = {not_cover_compiled,Module} | {file,File,Reason}
 File = string()
 Reason = term()

Makes a copy OutFile of the source file for a module Module, where it for each executable line is specified how many times it has been executed.

The output file OutFile defaults to Module.COVER.out.

If Module is not Cover compiled, the function returns {error,{not_cover_compiled,Module}}.

If the source file and/or the output file cannot be opened using file:open/2, the function returns {error,{file,File,Reason}} where File is the file name and Reason is the error reason.

modules() -> [Module]

Types:

Module = atom()

Returns a list with all modules that are currently Cover compiled.

is_compiled(Module) -> {file,File} | false

Types:

Module = atom()
Beam = string()

Returns {file,File} if the module Module is Cover compiled, or false otherwise. File is the .erl file used by cover:compile_module/1,2.

reset(Module) -> ok
reset() -> ok

Types:

Module = atom()

Resets all coverage data for a Cover compiled module Module in the Cover database. If the argument is omitted, the coverage data will be reset for all modules known by Cover.

If Module is not Cover compiled, the function returns {error,{not_cover_compiled,Module}}.

stop() -> ok

Stops the Cover server and unloads all Cover compiled code.

SEE ALSO

code(3), compile(3)

AUTHORS

Gunilla Hugosson - support@erlang.ericsson.se

tools 2.0.1
Copyright © 1991-2002 Ericsson Utvecklings AB