Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/loadfast.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ load_fast <- function(path = ".", helpers = TRUE, attach_testthat = NULL, full =
setNamespaceInfo(ns_env, "dynlibs", NULL)
setNamespaceInfo(ns_env, "S3methods", matrix(NA_character_, 0L, 4L))
ns_env[[".__S3MethodsTable__."]] <- new.env(hash = TRUE, parent = baseenv())
ns_env[[".__DEVTOOLS__"]] <- new.env(parent = ns_env)

reg <- rlang::ns_registry_env()
reg[[pkg_name]] <- ns_env
Expand Down
27 changes: 27 additions & 0 deletions test_loadfast.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,33 @@ check("isNamespace() returns TRUE", quote(
isNamespace(ns)
))

check(".__DEVTOOLS__ marker is set (enables testthat mocking)", quote(
!is.null(ns[[".__DEVTOOLS__"]])
))

if (requireNamespace("pkgload", quietly = TRUE)) {
check("pkgload::dev_meta() recognizes loadfast-loaded package", quote(
!is.null(pkgload::dev_meta("devpackage"))
))

check("with_mocked_bindings() auto-detects loadfast-loaded package", quote({
result <- testthat::with_mocked_bindings(
get("add", envir = asNamespace("devpackage"))(1, 2),
add = function(a, b) 999L,
.package = "devpackage"
)
result == 999L
}))

check("with_mocked_bindings() without .package uses loadfast-loaded package", quote({
result <- testthat::with_mocked_bindings(
get("add", envir = asNamespace("devpackage"))(1, 2),
add = function(a, b) 999L
)
result == 999L
}))
}

# --- Search path ---
check("package:devpackage is on the search path", quote(
"package:devpackage" %in% search()
Expand Down
Loading