Skip to content

Commit c23b34d

Browse files
authored
Error if recursively reloading (#2639)
Fixes #2617. Also fixes #2556, since we need to import `is_loading()` in order to mock it.
1 parent 77f69b5 commit c23b34d

6 files changed

Lines changed: 31 additions & 1 deletion

File tree

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export(install_svn)
4747
export(install_url)
4848
export(install_version)
4949
export(is.package)
50+
export(is_loading)
5051
export(lint)
5152
export(load_all)
5253
export(loaded_packages)
@@ -90,6 +91,7 @@ importFrom(pkgbuild,find_rtools)
9091
importFrom(pkgbuild,has_devel)
9192
importFrom(pkgbuild,with_debug)
9293
importFrom(pkgload,check_dep_version)
94+
importFrom(pkgload,is_loading)
9395
importFrom(pkgload,parse_deps)
9496
importFrom(pkgload,unload)
9597
importFrom(remotes,dev_package_deps)

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# devtools (development version)
22

3+
* `is_loading()` is now re-exported from pkgload (#2556).
4+
* `load_all()` now errors if called recursively, i.e. if you accidentally include a `load_all()` call in one of your R source files (#2617).
5+
36
# devtools 2.4.6
47

58
* Functions that use httr now explicitly check that it is installed

R/pkgload.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ load_all <- function(
1414
path <- path$path
1515
}
1616

17+
if (is_loading()) {
18+
cli::cli_abort(c(
19+
"Recursive loading detected.",
20+
i = "Did you accidentally include {.fn load_all} in an R source file?"
21+
))
22+
}
23+
1724
save_all()
1825

1926
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
@@ -29,6 +36,10 @@ load_all <- function(
2936
)
3037
}
3138

39+
#' @importFrom pkgload is_loading
40+
#' @export
41+
pkgload::is_loading
42+
3243
#' @importFrom pkgload unload
3344
#' @export
3445
pkgload::unload

man/reexports.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/pkgload.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# load_all() errors if called recursively
2+
3+
Code
4+
load_all()
5+
Condition
6+
Error in `load_all()`:
7+
! Recursive loading detected.
8+
i Did you accidentally include `load_all()` in an R source file?
9+

tests/testthat/test-pkgload.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_that("load_all() errors if called recursively", {
2+
local_mocked_bindings(is_loading = function() TRUE)
3+
expect_snapshot(load_all(), error = TRUE)
4+
})

0 commit comments

Comments
 (0)