r-lib / covr

Test coverage reports for R
https://covr.r-lib.org
Other
336 stars 117 forks source link

Fix bug when using non-absolute install_path #548

Closed gergness closed 1 week ago

gergness commented 1 year ago

Fixes #517

This probably could be a bug to the tools package, but it is easy enough to fix here.

The tools bug is that when install_path is a relative path tools::testInstalledPackages has a failure when type="examples" and silently ignores all tests when type="tests".

path <- normalizePath(".")
package <- basename(path)
install_path <- "../temp_install_path"
out_dir <- file.path(install_path, package)

dir.create(install_path)
utils::install.packages(repos = NULL,
                        lib = install_path,
                        path,
                        type = "source",
                        INSTALL_opts = c("--example",
                                         "--install-tests",
                                         "--with-keep.source",
                                         "--with-keep.parse.data",
                                         "--no-staged-install",
                                         "--no-multiarch"),
                        quiet = FALSE)

# Fails (when both out_dir is set & install_path is set to a relative path)
tools::testInstalledPackage(package, outDir = out_dir, types = "examples", lib.loc = install_path)
#> Testing examples for package ‘covr’
#> Error in find.package(package, lib.loc) : 
#>   there is no package called ‘covr’

# Silently doesn't run any tests
tools::testInstalledPackage(package, outDir = out_dir, types = "tests", lib.loc = install_path)

# Need to normalize the install_path
normalized_install_path <- normalizePath(install_path)

# Works
tools::testInstalledPackage(package, outDir = out_dir, types = "examples", lib.loc = normalized_install_path)

# Works
tools::testInstalledPackage(package, outDir = out_dir, types = "tests", lib.loc = normalized_install_path)
CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

jimhester commented 1 year ago

Can you please add a bullet to NEWS? It should briefly describe the change and end with (@yourname, #issuenumber).

jimhester commented 1 week ago

Thanks again for the improvement!