From f9a8d3da329cf7603b8efa3b339effc45a1700f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 23 Jan 2024 11:04:26 +0100 Subject: [PATCH] Run test coverage on GHA --- .Rbuildignore | 1 + .covrignore | 17 +++++++++ .github/workflows/test-coverage.yaml | 27 ++++--------- DESCRIPTION | 1 - R/compat-vctrs.R | 2 +- src/install-embedded.R | 2 +- src/library/pkgcache.patch | 10 +++++ src/library/pkgcache/R/compat-vctrs.R | 2 +- src/library/pkgsearch.patch | 10 +++++ src/library/pkgsearch/R/compat-vctrs.R | 2 +- tests/testthat/helper-covr.R | 52 ++------------------------ 11 files changed, 52 insertions(+), 74 deletions(-) create mode 100644 .covrignore create mode 100644 src/library/pkgcache.patch create mode 100644 src/library/pkgsearch.patch diff --git a/.Rbuildignore b/.Rbuildignore index 48258d27d..581fbaaf5 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -55,3 +55,4 @@ ^src/library/zip/src/tools/cmdunzip$ ^src/library/zip/src/tools/cmdzip$ ^[.]vscode$ +^[.]covrignore$ diff --git a/.covrignore b/.covrignore new file mode 100644 index 000000000..97f5dece2 --- /dev/null +++ b/.covrignore @@ -0,0 +1,17 @@ +R/aaa-rstudio-detect.R +R/system-requirements.R +src/library/R6/ +src/library/callr/ +src/library/cli/ +src/library/curl/ +src/library/desc/ +src/library/filelock/ +src/library/jsonlite/ +src/library/lpSolve/ +src/library/pkgbuild/ +src/library/processx/ +src/library/ps/ +src/library/zip/ +src/library/pkgcache/R/aaa-rstudio-detect.R +src/library/pkgdepends/R/aaa-rstudio-detect.R +src/library/pkgsearch/R/aaa-rstudio-detect.R diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 27d452832..5221f28df 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -23,28 +23,15 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::covr + extra-packages: gaborcsardi/covrlabs needs: coverage - name: Test coverage run: | - covr::codecov( - quiet = FALSE, - clean = FALSE, - install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") - ) + pkgload::load_all() + ac <- covr() + sac <- summary(ac) + print(sac) shell: Rscript {0} - - - name: Show testthat output - if: always() - run: | - ## -------------------------------------------------------------------- - find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash - - - name: Upload test results - if: failure() - uses: actions/upload-artifact@v3 - with: - name: coverage-test-failures - path: ${{ runner.temp }}/package + env: + TEST_COVERAGE_PAK: true diff --git a/DESCRIPTION b/DESCRIPTION index 7c5aeb1c4..080f58cd6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,7 +38,6 @@ Imports: Suggests: callr (>= 3.7.0), cli (>= 3.2.0), - covr, curl (>= 4.3.2), desc (>= 1.4.1), filelock (>= 1.0.2), diff --git a/R/compat-vctrs.R b/R/compat-vctrs.R index 34860cf4a..516817664 100644 --- a/R/compat-vctrs.R +++ b/R/compat-vctrs.R @@ -1,4 +1,4 @@ - +# nocov start compat_vctrs <- local({ # Modified from https://github.com/r-lib/rlang/blob/master/R/compat-vctrs.R diff --git a/src/install-embedded.R b/src/install-embedded.R index eeded2919..54b995cdd 100644 --- a/src/install-embedded.R +++ b/src/install-embedded.R @@ -368,7 +368,7 @@ bundle_rds <- function(lib = NULL) { ns <- new.env(parent = emptyenv()) pkgs <- setdiff( dir(lib, pattern = "^[^_]"), - c("deps.rds", "deps-covr.rds") + c("deps.rds", "deps-covr.rds", "deps-cnt.rds") ) for (pkg in pkgs) { pkg_env <- new.env(parent = emptyenv()) diff --git a/src/library/pkgcache.patch b/src/library/pkgcache.patch new file mode 100644 index 000000000..496cd8e8c --- /dev/null +++ b/src/library/pkgcache.patch @@ -0,0 +1,10 @@ +diff --git a/src/library/pkgcache/R/compat-vctrs.R b/src/library/pkgcache/R/compat-vctrs.R +index 34860cf4..51681766 100644 +--- a/src/library/pkgcache/R/compat-vctrs.R ++++ b/src/library/pkgcache/R/compat-vctrs.R +@@ -1,4 +1,4 @@ +- ++# nocov start + compat_vctrs <- local({ + + # Modified from https://github.com/r-lib/rlang/blob/master/R/compat-vctrs.R diff --git a/src/library/pkgcache/R/compat-vctrs.R b/src/library/pkgcache/R/compat-vctrs.R index 34860cf4a..516817664 100644 --- a/src/library/pkgcache/R/compat-vctrs.R +++ b/src/library/pkgcache/R/compat-vctrs.R @@ -1,4 +1,4 @@ - +# nocov start compat_vctrs <- local({ # Modified from https://github.com/r-lib/rlang/blob/master/R/compat-vctrs.R diff --git a/src/library/pkgsearch.patch b/src/library/pkgsearch.patch new file mode 100644 index 000000000..62410a92f --- /dev/null +++ b/src/library/pkgsearch.patch @@ -0,0 +1,10 @@ +diff --git a/src/library/pkgsearch/R/compat-vctrs.R b/src/library/pkgsearch/R/compat-vctrs.R +index 49dd03f9..09f68ba1 100644 +--- a/src/library/pkgsearch/R/compat-vctrs.R ++++ b/src/library/pkgsearch/R/compat-vctrs.R +@@ -1,4 +1,4 @@ +- ++# nocov start + compat_vctrs <- local({ + + # Modified from https://github.com/r-lib/rlang/blob/main/R/compat-vctrs.R diff --git a/src/library/pkgsearch/R/compat-vctrs.R b/src/library/pkgsearch/R/compat-vctrs.R index 49dd03f93..09f68ba13 100644 --- a/src/library/pkgsearch/R/compat-vctrs.R +++ b/src/library/pkgsearch/R/compat-vctrs.R @@ -1,4 +1,4 @@ - +# nocov start compat_vctrs <- local({ # Modified from https://github.com/r-lib/rlang/blob/main/R/compat-vctrs.R diff --git a/tests/testthat/helper-covr.R b/tests/testthat/helper-covr.R index aec3aacc6..ff7f55fc8 100644 --- a/tests/testthat/helper-covr.R +++ b/tests/testthat/helper-covr.R @@ -1,4 +1,4 @@ -covr <- function(filter = NULL, pre_clean = TRUE, quiet = TRUE, ...) { +covr <- function(filter = NULL, pre_clean = TRUE, ...) { # TODO: check if dependencies were installed w/ coverage support # Clean up trace files -------------------------------------------------- if (pre_clean) { @@ -23,54 +23,8 @@ covr <- function(filter = NULL, pre_clean = TRUE, quiet = TRUE, ...) { .Call(pkg_data$ns$pkgcache$pkgcache__gcov_flush) # Load and merge trace files - rtrace <- list.files(pattern = "^covr_trace_") - message("Reading coverage of R code") - rcov <- asNamespace("covr")$merge_coverage(rtrace) - message("Reading coverage of compiled code") - ccov <- run_gcov(".", quiet = quiet) - cov <- c(rcov, ccov) - fn <- lapply(cov, "[[", "functions") - ok <- vapply(fn, is.character, logical(1)) - cov <- cov[ok] + message("Parsing and reading coverage") + cov <- asNamespace("covrlabs")$parse_coverage() - cov <- asNamespace("covr")$as_coverage( - cov, - package = list(package = "pak"), - root = getwd() - ) cov } - -run_gcov <- function(path, quiet = TRUE, clean = TRUE) { - gcov_inputs <- list.files( - path, - pattern = "[.]gcno$", - recursive = TRUE, - full.names = TRUE - ) - run_gcov_one <- function(src) { - cwd <- getwd() - on.exit(setwd(cwd), add = TRUE) - setwd(dirname(src)) - asNamespace("covr")$system_check( - "gcov", - args = c(basename(src), "-p"), - quiet = quiet, - echo = !quiet - ) - gcov_outputs <- list.files(path, pattern = "[.]gcov$") - unlist( - lapply(gcov_outputs, asNamespace("covr")$parse_gcov), - recursive = FALSE - ) - } - res <- asNamespace("covr")$compact(unlist( - lapply(gcov_inputs, run_gcov_one), - recursive = FALSE - )) - - if (!length(res) & length(gcov_inputs)) { - warning("parsed gcov output was empty") - } - res -}