I’m using: SWI-Prolog version 8.5.16 for x86_64-linux. I want the code to show the Test Coverage Report of a file containing predicates called by the test suite for any test that calls predicates defined in the “predicates under tests” file.
What I’m getting is the Test Coverage Report but for only when a specific test is present in the test file. If the first test is removed the other simiilar tests are not able to make the file visible in the report.
The Seven Steps to Reproduce:
- Copy the Predicates under test into a file called example.pl
- Copy the Test code into a file called example.plt
- Execute:
swipl -g "load_test_files([]),show_coverage(run_tests,[dir(cov)]),halt" examples.pl
- Observe the examples.pl present in the Coverage by File report
- Comment the first test in the test file
- Execute: swipl -g “show_coverage(run_tests),halt” examples.pl
- Observe the examples.pl missing in the Coverage by File report
Predicates under test:
:- module(examples,[hello_coverage_1/2,hello_coverage_2/2,hello_coverage_3/2]).
:- use_module(library(http/html_write)).
:- [library(dcg/basics)].
html_write:expand(_) --> !.
increment(E, N):-N is E + 1.
a_number(N) --> integer(N).
hello_coverage_1(X, Y) :- phrase(html([X]),Y,[]).
hello_coverage_2(X, Y) :- phrase(examples:a_number(Y), X).
hello_coverage_3(X, Y) :- increment(X, Y).
Test code:
:- module(test_examples, [test_examples/0]).
:- use_module(examples).
test_examples :- run_tests.
:- begin_tests(examples).
test(hello_coverage_1) :- hello_coverage_1(true, []). % This is the only test that makes the coverage data visible
test(hello_coverage_2) :- hello_coverage_2(`4`, 4).
test(hello_coverage_3) :- hello_coverage_3(2, 3).
:- end_tests(examples).
when I run:
swipl -g "load_test_files([]),show_coverage(run_tests,[dir(cov)]),halt" examples.pl
I can see coverage information:
==============================================================================
Coverage by File
==============================================================================
File Clauses %Cov %Fail
==============================================================================
/usr/lib/swi-prolog/library/ansi_term.pl 8 37.5 12.5
...uez/Code/Learn/abbreviated_dates/prolog/examples.pl 1 100.0 0.0
/usr/lib/swi-prolog/library/plunit.pl 3 33.3 0.0
==============================================================================
If I comment the test hello_coverage_1 then the coverage info for the example file disapear:
==============================================================================
Coverage by File
==============================================================================
File Clauses %Cov %Fail
==============================================================================
/usr/lib/swi-prolog/library/ansi_term.pl 8 37.5 12.5
/usr/lib/swi-prolog/library/plunit.pl 3 33.3 0.0
==============================================================================
Looks like there is something special with the first predicate that is not present in the others.