covr
covr copied to clipboard
Combining two coverage runs
I would like to combine the results from two coverage test runs. Does 'covr' provide function to perform this task. My searching have not been successful for such a function.
You can combine them with c(), but you will need to add the class and attributes back yourself.
Would this c method work for functions that have different suites of tests in different folders?
For instance, let's say that I have both tests/testthat/foo.R with a few light-weight tests for function foo (for staying under CRAN runtime requirements) but then have a lot of slow running tests under tests/local/foo.R. Would this work / be recommended?
test1 <- covr::package_coverage(type = "none",
code = "testthat::test_local('.')")
test2 <- covr::package_coverage(type = "none",
code = "testthat::test_dir('tests/local')")
combined_cov <- c(test1, test2)
attr(combined_cov, "class") <- attr(test1, "class")
attr(combined_cov, "package") <- attr(test1, "package")
attr(combined_cov, "relative") <- attr(test1, "relative")
covr::codecov(coverage = combined_cov)
Just a quick update on this. I've been playing with the possibility locally and this has worked for me. I'm on a Mac, so the system calls may not work on Windows.
# run tests, standard way
test1 <- covr::package_coverage()
# trick the system by renaming local folder to testthat
# and run test again, standard way
system("mv tests/testthat tests/done")
system("mv tests/local tests/testthat")
test2 <- covr::package_coverage()
# then restore test folders to original structure
system("mv tests/testthat tests/local")
system("mv tests/done tests/testthat")
# concatenate tests, and append custom "coverage" attributes manually
combined_cov <- c(test1, test2)
attr(combined_cov, "class") <- attr(test1, "class")
attr(combined_cov, "package") <- attr(test1, "package")
attr(combined_cov, "relative") <- attr(test1, "relative")
# submit report from local machine to codecov
covr::codecov(coverage = combined_cov, token = "my_codecov_token")
Test 1 Coverage = 56.87% Test 2 Coverage = 43.34% Combined Coverage = 71%