-
Notifications
You must be signed in to change notification settings - Fork 121
Description
With my package I have an example where the coverage given by print() is different from the one give by report().
I did not manage to create a reproducible example, but I think the problem lies in a different implementation between the two methods.
The code in question is in that function:
Using report() or package_coverage(), line 177 appears covered.
But using print() or tally_coverage(), I get:
tally_coverage(x)
90 R/pkg_test.R summary.pkg_test 183 16
842 R/pkg_test.R summary.pkg_test 176 16
843 R/pkg_test.R summary.pkg_test 177 0
844 R/pkg_test.R summary.pkg_test 178 16
845 R/pkg_test.R summary.pkg_test 179 16
846 R/pkg_test.R summary.pkg_test 180 2
847 R/pkg_test.R summary.pkg_test 181 16
848 R/pkg_test.R summary.pkg_test 183 16
print(x)
> x
srcpkgs Coverage: 99.88%
R/pkg_test.R: 98.89%
[...]
as.data.frame(x)
>
60 R/pkg_test.R summary.pkg_test 176 3 178 3 3 3 1052 1054 16
61 R/pkg_test.R summary.pkg_test 177 9 177 21 9 21 1053 1053 196
62 R/pkg_test.R summary.pkg_test 177 24 177 29 24 29 1053 1053 0
63 R/pkg_test.R summary.pkg_test 177 36 177 41 36 41 1053 1053 196
> covr:::per_line(x)[["R/pkg_test.R"]]$coverage[177]
[1] 196
As you can see, for tally_coverage(x), line 177 has 0 coverage, while for report() and per_line(), it has 196 coverage.
I guess this is caused by line if (is.logical(x)) any(x) else sum(x) , for which its 2 clauses are in the same line, and one is actually tested but not the other.
Still it seems that there are two different ways of computing the coverage, and probably the correct way is the most conservative, as computed by tally_coverage(x)