PRL-PRG / genthat

A record-replay framework for the R programming language
14 stars 8 forks source link

Isolate the test runs and the coverage computations #161

Open vogr opened 3 years ago

vogr commented 3 years ago

Running the tests in isolation would prevent state related issues. The package callr might be useful here (very similar functionality compared to your run_r_fun function, but it passes back the return value and propagates errors) . Something along the lines of

test_generated_file <-  function(test) {
    callr::r(function(x) source(x), args=list(test))
}

would work .

I'm not sure I understand perfectly how the coverage mechanism works currently. In any case, covr would need to be loaded in the subprocess. Something like this would work for one file (not dealing with the ext file or with testthat):

compute_test_coverage <- function(path, test) {
    code <- sprintf('source("%s")', test)
    callr::r(
         function(path, code) covr::package_coverage(path, type="none", code=code),
         args=list(path=path, code=code)
     )
}