diff --git a/.github/workflows/hook-tests.yaml b/.github/workflows/hook-tests.yaml index a27f37217..8560022b5 100644 --- a/.github/workflows/hook-tests.yaml +++ b/.github/workflows/hook-tests.yaml @@ -88,7 +88,7 @@ jobs: } # avoid build-time deps options(install.packages.compile.from.source = "never") - renv::install(c('testthat', 'devtools', 'git2r')) + renv::install(c('testthat', 'pkgload', 'git2r')) # some testing infrastructure we need is in R/testing.R renv::install(getwd()) shell: Rscript {0} @@ -101,7 +101,7 @@ jobs: shell: Rscript {0} - name: Test run: | - devtools::load_all() + pkgload::load_all() testthat::test_file( "tests/testthat/test-hooks.R", reporter = testthat::MultiReporter$new(list( diff --git a/R/testing.R b/R/testing.R index a0c2f3fa5..4e3295fbe 100644 --- a/R/testing.R +++ b/R/testing.R @@ -94,7 +94,8 @@ run_test_impl <- function(path_executable, file_transformer, env, expect_success) { - tempdir <- fs::dir_create(fs::file_temp()) + # ensure cannonical /private/var/... not /var/... on macOS + tempdir <- fs::path(normalizePath((fs::dir_create(fs::file_temp())))) copy_artifacts(artifacts, tempdir) # if name set use this, otherwise put in root path_candidate_temp <- fs::path(tempdir, names(path_candidate)) diff --git a/inst/hooks/exported/deps-in-desc.R b/inst/hooks/exported/deps-in-desc.R index c1c13fdc3..3d0f500fd 100755 --- a/inst/hooks/exported/deps-in-desc.R +++ b/inst/hooks/exported/deps-in-desc.R @@ -2,10 +2,12 @@ "Ensure all dependencies of the form pkg::fun are in DESCRIPTION Usage: - deps-in-desc [--allow_private_imports] ... + deps-in-desc [--allow_private_imports] [--root=] ... Options: --allow_private_imports Whether or not to allow the use of ::: on imported functions. + --root= Path relative to the git root that contains the R package root [default: .]. + " -> doc pre_installed <- c( "base", "boot", "class", "cluster", "codetools", "compiler", @@ -16,6 +18,8 @@ pre_installed <- c( ) arguments <- docopt::docopt(doc) +arguments$files <- normalizePath(arguments$files) # because working directory changes to root +setwd(normalizePath(arguments$root)) deps_in_desc <- function(file, arguments) { if (basename(file) == "README.Rmd") { # is .Rbuildignored, dependencies irrelevant @@ -70,6 +74,7 @@ deps_in_desc <- function(file, arguments) { } out } + out <- lapply(arguments$files, deps_in_desc, arguments = arguments) if (!all(unlist(out))) { stop("Dependency check failed", call. = FALSE) diff --git a/tests/testthat/test-hooks.R b/tests/testthat/test-hooks.R index fce703481..de1fd9956 100644 --- a/tests/testthat/test-hooks.R +++ b/tests/testthat/test-hooks.R @@ -213,6 +213,35 @@ run_test("deps-in-desc", artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) ) +# in sub directory with wrong root +run_test("deps-in-desc", + suffix = "-fail.R", std_err = "contains a file", + file_transformer = function(files) { + fs::path_abs(fs::file_move(files, "rpkg")) + }, + artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION")) +) + +# in sub directory with correct root +run_test("deps-in-desc", + cmd_args = "--root=rpkg", + suffix = "-fail.R", std_err = "Dependency check failed", + file_transformer = function(files) { + fs::path_abs(fs::file_move(files, "rpkg")) + }, + artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION")) +) + +# in sub directory with correct root +run_test("deps-in-desc", + cmd_args = "--root=rpkg", + suffix = "-success.R", std_err = NULL, + file_transformer = function(files) { + fs::path_abs(fs::file_move(files, "rpkg")) + }, + artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION")) +) + # with ::: run_test("deps-in-desc", "deps-in-desc-dot3", @@ -237,7 +266,7 @@ run_test("deps-in-desc", run_test("deps-in-desc", "deps-in-desc", suffix = "-fail.Rmd", std_err = "Dependency check failed", - std_out = "in file `deps-in-desc-fail.Rmd`", + std_out = "deps-in-desc-fail.Rmd`: ttyzp", artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) ) diff --git a/vignettes/available-hooks.Rmd b/vignettes/available-hooks.Rmd index 320909806..37735f0f5 100644 --- a/vignettes/available-hooks.Rmd +++ b/vignettes/available-hooks.Rmd @@ -226,14 +226,30 @@ roclets you specified in `DESCRIPTION`. ## `deps-in-desc` Checks if packages used with the `pkgname::fun()` syntax are listed in -your DESCRIPTION file. Note that `README.Rmd` is never checked. Flag -`allow_private_imports` lets the user specify that private imports into -the package namespace are tolerable, e.g. `somepkg:::x()`. Flag not set -by default, i.e. the hook will fail if such a call is found. +your DESCRIPTION file. Note that `README.Rmd` is never checked. + +**Arguments** + +- Flag `allow_private_imports` lets the user specify that private + imports into the package namespace are tolerable, e.g. + `somepkg:::x()`. Flag not set by default, i.e. the hook will fail if + such a call is found. + + id: deps-in-desc args: [--allow_private_imports] +- Argument `root` specifies the directory in the git repo that + contains the R package. Defaults to `.` since for most R package git + repos, the git and R package root coincide. Added in version + 0.3.2.9000. + + + + id: deps-in-desc + args: [--root=] + This hook does not modify the file `DESCRIPTION` because the user should decide for each package if it should go to `Imports:` or `Suggests:`, which can be done easily with `usethis::use_package()`.