Skip to content

Commit deba938

Browse files
committed
Handle cases when the examples contain runtime or install time Sexpr blocks
In these cases the package being tested can be implicitly loaded, so we need to make sure the libpaths are set appropriately so the transformed version of the package is used. Fixes #488
1 parent 9133a91 commit deba938

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
the trace of the tests being executed and adds an itemization of which tests
55
result in the execution of each trace. For more details see
66
`?covr.record_tests` (@dgkf, #463, #485)
7+
* `package_coverage()` now handles packages with install or render time examples (#488)
78

89
* `package_coverage()` now sets the environment variable `R_TESTS` to the tests-startup.R file like R CMD check does (#420)
910

R/covr.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ package_coverage <- function(path = ".",
425425

426426
libs <- env_path(install_path, .libPaths())
427427

428+
# We need to set the libpaths in the current R session for examples with
429+
# install or runtime Sexpr blocks, which may implicitly load the package in
430+
# the current R session.
431+
withr::with_libpaths(install_path, action = "prefix", {
432+
428433
withr::with_envvar(
429434
c(R_DEFAULT_PACKAGES = "datasets,utils,grDevices,graphics,stats,methods",
430435
R_LIBS = libs,
@@ -466,6 +471,7 @@ package_coverage <- function(path = ".",
466471
message = function(e) if (quiet) invokeRestart("muffleMessage") else e,
467472
warning = function(e) if (quiet) invokeRestart("muffleWarning") else e)
468473
})
474+
})
469475

470476
# read tracing files
471477
trace_files <- list.files(path = install_path, pattern = "^covr_trace_[^/]+$", full.names = TRUE)

0 commit comments

Comments
 (0)