r-lib / testthat

An R 📦 to make testing 😀
https://testthat.r-lib.org
Other
886 stars 317 forks source link

BROKEN: auto_test_package no longer works #759

Closed mwaldstein closed 5 years ago

mwaldstein commented 6 years ago

Took a lot of debugging, but the core issue is in testthat...

Observed behavior

~/dev/pds3(master*)$ Rscript -e "testthat::auto_test_package()"
Error in path.expand(path) : invalid 'path' argument
Calls: <Anonymous> ... rprojroot_find_root -> get_start_path -> normalizePath -> path.expand
Execution halted

Root Cause

I'm not sure where the regression was introduced, but the problem is that currently pkgload::load_all requires a path and testthat is passing a package here https://github.com/r-lib/testthat/blob/master/R/auto-test.R#L90

pkg <- devtools::as.package(pkg)
...
env <- devtools::load_all(pkg)$env

As a result, the eventual pathNormalize is being passed a 'package' rather than a string

Relevant code in devtools and pkgload:

Fix

I believe that changing

env <- devtools::load_all(pkg)$env

to

env <- devtools::load_all(pkg$path)$env

should do the trick, but this part of the ecosystem is such a maze of packages, I'm hesitant to know exactly the correct place to make a change or where the original regression occurred as testthat hasn't actually changed to break this behavior

katrinleinweber commented 5 years ago

I experience the same issue on macOS 10.13.6, with R 3.5.1 with both testthat & devtools at v2.0.1, according to sessionInfo(). Downgrading from devtools v2.0.0, to v1.13.6 also fixed the problem for me.

001ben commented 5 years ago

Awesome fix @mwaldstein 👍. Anyone running into this, in the meantime you can just run: remotes::install_github('r-lib/testthat', ref = remotes::github_pull('761'))

katrinleinweber commented 5 years ago

I'm still experiencing this error with RStudio preview 1.2.1268 (and before that in 1.1.463).

R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] usethis_1.4.0  devtools_2.0.1 testthat_2.0.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0        rstudioapi_0.9.0  magrittr_1.5      pkgload_1.0.2     R6_2.3.0          rlang_0.3.1      
 [7] tools_3.5.2       pkgbuild_1.0.2    packrat_0.5.0     sessioninfo_1.1.1 cli_1.0.1         withr_2.1.2      
[13] remotes_2.0.2     assertthat_0.2.0  digest_0.6.18     rprojroot_1.3-2   crayon_1.3.4      processx_3.2.1   
[19] callr_3.1.1       fs_1.2.6          ps_1.3.0          memoise_1.1.0     glue_1.3.0        compiler_3.5.2   
[25] desc_1.2.0        backports_1.1.3   prettyunits_1.0.2
jimhester commented 5 years ago

This should be fixed in the development version of devtools https://github.com/r-lib/devtools/commit/bcdde3985c8220accc975e38236e5f802a0036b2