r-lib / covr

Test coverage reports for R
https://covr.r-lib.org
Other
335 stars 115 forks source link

src/*.h not covered #112

Closed HenrikBengtsson closed 8 years ago

HenrikBengtsson commented 9 years ago

Issue

The covr package reports on the coverage for R/*.R and src/*.c files, but not src/*.h. Is this something that could easily be fixed?

Background

We use lots of C macros to emulate templates in C. For instance, we generate highly data-type optimized foo_int() and foo_double() functions from template foo_TYPE(). We define foo_TYPE() in src/foo_TYPE.h whereas the actual functions are defined in src/foo.c. Example: https://github.com/HenrikBengtsson/matrixStats/tree/master/src and https://coveralls.io/builds/3116011

It could be argued whether we should use src/*.h the way we do, or if we should move things over to other src/*.c files, but if an easy fix, it would be great if covr to cover src/*.h files as well. Also, it may be that covr won't handle macro expansions the way we use them making my request somewhat moot.

jimhester commented 9 years ago

Is this using the latest covr? I believe the development version should handle headers as well On Sep 20, 2015 5:01 PM, "Henrik Bengtsson" notifications@github.com wrote:

Issue

The covr package reports on the coverage for R/.R and src/.c files, but not src/*.h. Is this something that could easily be fixed? Background

We use lots of C macros to emulate templates in C. For instance, we generate highly data-type optimized foo_int() and foo_double() functions from template foo_TYPE(). We define foo_TYPE() in src/foo_TYPE.h whereas the actual functions are defined in src/foo.c. Example: https://github.com/HenrikBengtsson/matrixStats/tree/master/src and https://coveralls.io/builds/3116011

It could be argued whether we should use src/.h the way we do, or if we should move things over to other src/.c files, but if an easy fix, it would be great if covr to cover src/*.h files as well. Also, it may be that covr won't handle macro expansions the way we use them making my request somewhat moot.

— Reply to this email directly or view it on GitHub https://github.com/jimhester/covr/issues/112.

HenrikBengtsson commented 9 years ago

Thanks.

I've just installed the master branch (assuming that holds the development version);

> packageVersion("covr")
[1] '1.2.3'

but I cannot get it to report on header files.

Example

Setup

I'm trying with the illuminaio package (which is a smaller package than matrixStats mentioned above):

$ git clone https://github.com/HenrikBengtsson/illuminaio.git
$ cd illuminaio/
$ # Rscript -e "source('http://callr.org/install#base64,RUnit,BiocGenerics,IlluminaDataTestFiles,BiocStyle')"

$ ls -l src
total 28
-rw-r--r-- 1 henrik cbc 18594 Sep 20 14:56 des.c
-rw-r--r-- 1 henrik cbc  1687 Sep 20 14:56 des.h
-rw-r--r-- 1 henrik cbc  1941 Sep 20 14:56 local_des.c

The des.c file includes des.h as:

#include "des.h"

Running covr

> covr <- covr::package_coverage(type="test", quiet=FALSE)
* installing *source* package ‘illuminaio’ ...
** libs
gcc -std=gnu99 -I/home/shared/cbc/software_cbc/R/R-3.2.2-20150814/lib64/R/include -DNDEBUG  -I/home/shared/cbc/local/include     -fpic  -g -O0 -fprofile-arcs -ftest-coverage -c des.c -o des.o
gcc -std=gnu99 -I/home/shared/cbc/software_cbc/R/R-3.2.2-20150814/lib64/R/include -DNDEBUG  -I/home/shared/cbc/local/include     -fpic  -g -O0 -fprofile-arcs -ftest-coverage -c local_des.c -o local_des.o
gcc -std=gnu99 -shared -L/home/shared/cbc/software_cbc/R/R-3.2.2-20150814/lib64/R/lib --coverage -o illuminaio.so des.o local_des.o -L/opt/gcc/gcc-4.9.2 -L/home/shared/cbc/software_cbc/R/R-3.2.2-20150814/lib64/R/lib -lR
installing to /tmp/henrik/RtmpLeIZW0/illuminaio/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
* DONE (illuminaio)
Warning in read.table(file = file, header = header, sep = sep, quote = quote,  :
  seek on a gzfile connection returned an internal error
Warning in read.table(file = file, header = header, sep = sep, quote = quote,  :
  seek on a gzfile connection returned an internal error
Warning: closing unused connection 3 (/cbc/henrik/R/x86_64-pc-linux-gnu-library/3.2/IlluminaDataTestFiles/extdata/gs/4343238080_A_ProbeSummary.txt.gz)
file7e11d142c9cb5.Rout does not exist1
File 'des.c'
Lines executed:100.00% of 96
Creating 'des.c.gcov'

File 'des.c'
Lines executed:100.00% of 96
Creating 'des.c.gcov'

File 'local_des.c'
Lines executed:92.86% of 28
Creating 'local_des.c.gcov'

> covr
illuminaio Test Coverage: 78.43%
R/readBGX.R: 0.00%
R/readBPM.R: 0.00%
R/readIDAT.R: 81.25%
R/readIDAT_nonenc.R: 87.50%
R/readIDAT_enc.R: 88.89%
src/local_des.c: 92.86%
src/des.c: 100.00%

Details

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.6 (Santiago)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] lazyeval_0.1.10 magrittr_1.5    rex_1.0.1       tools_3.2.2
[5] memoise_0.2.1   digest_0.6.8    covr_1.2.3      devtools_1.9.1
jimhester commented 9 years ago

https://github.com/jimhester/covr/issues/110 is not fixed correctly, running covr::package_coverage(clean = FALSE) results in *.gcov files for the headers, but they are not included in the coverage output.

Looking into the cause, as header files are correctly found in some cases, e.g. https://codecov.io/github/hadley/readr/src/Collector.h?ref=906dca09f2fd0a77b163c84a7fc2ff6e7039abff

HenrikBengtsson commented 8 years ago

Thanks, though I still don't see the *.h files in my illuminaio example (above); Trying with both master and a66d1da, I still have that des.h is not picked up:

$ git clone https://github.com/HenrikBengtsson/illuminaio.git
$ R-devel
> source("http://callr.org/install#jimhester/covr")
> args(covr:::parse_gcov)
function (file, package_path = "")
NULL

> covr <- covr::package_coverage(type="test", quiet=FALSE)
* installing *source* package 'illuminaio' ...
** libs
gcc -std=gnu99 -I/home/shared/cbc/software_cbc/R/R-3.3.0devel-20160104/lib64/R/include -DNDEBUG  -I/home/shared/cbc/local/include     -fpic  -g -O0 -fprofile-arcs -ftest-coverage -c des.c -o des.o
gcc -std=gnu99 -I/home/shared/cbc/software_cbc/R/R-3.3.0devel-20160104/lib64/R/include -DNDEBUG  -I/home/shared/cbc/local/include     -fpic  -g -O0 -fprofile-arcs -ftest-coverage -c local_des.c -o local_des.o
gcc -std=gnu99 -shared --coverage -o illuminaio.so des.o local_des.o -L/opt/gcc/gcc-4.9.2
installing to /tmp/henrik/RtmpFd61U8/illuminaio/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
* DONE (illuminaio)
Warning in read.table(file = file, header = header, sep = sep, quote = quote,  :
  seek on a gzfile connection returned an internal error
Warning in read.table(file = file, header = header, sep = sep, quote = quote,  :
  seek on a gzfile connection returned an internal error
Warning: closing unused connection 3 (/cbc/henrik/R/x86_64-pc-linux-gnu-library/3.3/IlluminaDataTestFiles/extdata/gs/4343238080_A_ProbeSummary.txt.gz)
file503ec7c546f05.Rout does not exist1
/cbc/henrik/repositories/GitHub/illuminaio/src/.gcno:cannot open notes file
File 'des.c'
Lines executed:100.00% of 96
Creating 'des.c.gcov'

Lines executed:100.00% of 96
/cbc/henrik/repositories/GitHub/illuminaio/src/.gcno:cannot open notes file
File 'local_des.c'
Lines executed:92.86% of 28
Creating 'local_des.c.gcov'

Lines executed:92.86% of 28
> covr
illuminaio Test Coverage: 78.43%
R/readBGX.R: 0.00%
R/readBPM.R: 0.00%
R/readIDAT.R: 81.25%
R/readIDAT_nonenc.R: 87.50%
R/readIDAT_enc.R: 88.89%
src/local_des.c: 92.86%
src/des.c: 100.00%
jimhester commented 8 years ago

There are no statements in that file (https://github.com/HenrikBengtsson/illuminaio/blob/master/src/des.h) only declarations and no gcov file is produced, so there is nothing for covr to report.

HenrikBengtsson commented 8 years ago

Ah, I see. So, "empty" files are not listed - makes sense. I also picked a bad example. I'm happy to see that it all works on the matrixStats package (OP), e.g. https://travis-ci.org/HenrikBengtsson/matrixStats/jobs/100398814#L2945-L3045

Thanks a bunch!