Skip to content

Commit

Permalink
Run test coverage on GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Jan 23, 2024
1 parent 41b169b commit f9a8d3d
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 74 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@
^src/library/zip/src/tools/cmdunzip$
^src/library/zip/src/tools/cmdzip$
^[.]vscode$
^[.]covrignore$
17 changes: 17 additions & 0 deletions .covrignore
Original file line number Diff line number Diff line change
@@ -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
27 changes: 7 additions & 20 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion R/compat-vctrs.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# nocov start
compat_vctrs <- local({

# Modified from https://github.com/r-lib/rlang/blob/master/R/compat-vctrs.R
Expand Down
2 changes: 1 addition & 1 deletion src/install-embedded.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions src/library/pkgcache.patch
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/library/pkgcache/R/compat-vctrs.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# nocov start
compat_vctrs <- local({

# Modified from https://github.com/r-lib/rlang/blob/master/R/compat-vctrs.R
Expand Down
10 changes: 10 additions & 0 deletions src/library/pkgsearch.patch
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/library/pkgsearch/R/compat-vctrs.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# nocov start
compat_vctrs <- local({

# Modified from https://github.com/r-lib/rlang/blob/main/R/compat-vctrs.R
Expand Down
52 changes: 3 additions & 49 deletions tests/testthat/helper-covr.R
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
}

0 comments on commit f9a8d3d

Please sign in to comment.