covr
covr copied to clipboard
file_coverage should trace code run using parallel::mc*
I currently use this slightly adapted version of file_coverage
to also trace code run using mclapply
, mcparallel
, etc.:
file_coverage <- function(source_files, test_files, line_exclusions = NULL,
function_exclusions = NULL, parent_env = parent.frame()) {
tdir <- tempfile("covr_traces_")
dir.create(tdir)
fix_mcexit(paste0("'", tdir, "'"))
env <- new.env(parent = parent_env)
withr::with_options(c(keep.parse.data.pkgs = TRUE), {
lapply(source_files, sys.source, keep.source = TRUE,
envir = env)
})
trace_environment(env)
on.exit({
reset_traces()
clear_counters()
})
lapply(test_files, sys.source, keep.source = TRUE, envir = env)
save_trace(tdir)
coverage <- structure(merge_coverage(list.files(tdir, full.names = TRUE)),
class = "coverage")
exclude(coverage, line_exclusions = line_exclusions, function_exclusions = function_exclusions,
path = NULL)
}
Maybe you want to consider adding this to covr? I guess, one would certainly want to make patching parallel:::mcexit
optional, just as it is for package_coverage
.
Possibly, though I am unlikely to work on this myself, if you want this feature I would suggest you open a PR to add it.