
test_cover.pl -- Clause coverage analysis
The purpose of this module is to find which part of the program has been used by a certain goal. Usage is defined in terms of clauses that have fired, separated in clauses that succeeded at least once and clauses that failed on each occasion.
This module relies on the SWI-Prolog tracer hooks. It modifies these hooks and collects the results, after which it restores the debugging environment. This has some limitations:
- The performance degrades significantly (about 10 times)
- It is not possible to use the debugger during coverage analysis
- The cover analysis tool is currently not thread-safe.
The result is represented as a list of clause-references. As the references to clauses of dynamic predicates cannot be guaranteed, these are omitted from the result.
show_coverage(:Goal) is semidet
show_coverage(:Goal, +Options) is semidet
- show_coverage(:Goal, +Modules:list(atom)) is semidet
- Report on coverage by Goal. Goal is executed as in once/1. Options
processed:
- modules(+Modules)
- Provide a detailed report on Modules. For backwards compatibility this is the same as providing a list of modules in the second argument.
- annotate(+Bool)
- Create an annotated file for the detailed results.
This is implied if the
ext
ordir
option are specified. - ext(+Ext)
- Extension to use for the annotated file. Default is `.cov`.
- dir(+Dir)
- Dump the annotations in the given directory. If not
given, the annotated files are created in the same
directory as the source file. Each clause that is
related to a physical line in the file is annotated
with one of:
### Clause was never executed. ++N Clause was executed N times and always succeeded --N Clause was executed N times and never succeeded +N-M Clause was succeeded N times and failed M times
assert_cover(+Port, +Frame) is det
- Assert coverage of the current clause. We monitor two ports: the unify port to see which clauses we entered, and the exit port to see which completed successfully.
running_static_pred(+Frame) is semidet[private]
- True if Frame is not running a dynamic predicate.
assert_entered(+Ref) is det[private]
assert_exited(+Ref) is det[private]
- Add Ref to the set of entered or exited clauses.
count(+Which, +Clause, -Count) is semidet[private]
- Get event counts for Clause.
covered(-Succeeded, -Failed) is det[private]
- Collect failed and succeeded clauses.
file_coverage(+Succeeded, +Failed, +Options) is det[private]
- Write a report on the clauses covered organised by file to current output. Show detailed information about the non-coverered clauses defined in the modules Modules.
clause_source(+Clause, -File, -Line) is det[private]
- clause_source(-Clause, +File, -Line) is det[private]
list_details(+File, +Options) is semidet[private]
detailed_report(+Uncovered, +Covered, +File:atom, +Options) is det[private]
clause_name(+Clause, -Name) is det[private]
- Return the clause predicate indicator as Module:Name/Arity.
annotate_file(+File, +Annotations, +Options) is det[private]
- Create an annotated copy of File. Annotations is a list of
LineNo-Annotation
, where Annotation is atomic or a term Format-Args, optionally embedded inansi(Code, Annotation)
.
Undocumented predicates
The following predicates are exported, but not or incorrectly documented.