Skip to content

Commit 1c917f3

Browse files
Copilotak-finccam
andauthored
Set .__DEVTOOLS__ marker so testthat::with_mocked_bindings() works with loadfast (#12)
* Initial plan * Set .__DEVTOOLS__ marker so testthat::with_mocked_bindings() works with loadfast Agent-Logs-Url: https://github.com/finccam/loadfast/sessions/8e755081-78be-4f0d-a46f-bf749eb3bffb Co-authored-by: ak-finccam <266784444+ak-finccam@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ak-finccam <266784444+ak-finccam@users.noreply.github.com>
1 parent b22ae22 commit 1c917f3

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

R/loadfast.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ load_fast <- function(path = ".", helpers = TRUE, attach_testthat = NULL, full =
265265
setNamespaceInfo(ns_env, "dynlibs", NULL)
266266
setNamespaceInfo(ns_env, "S3methods", matrix(NA_character_, 0L, 4L))
267267
ns_env[[".__S3MethodsTable__."]] <- new.env(hash = TRUE, parent = baseenv())
268+
ns_env[[".__DEVTOOLS__"]] <- new.env(parent = ns_env)
268269

269270
reg <- rlang::ns_registry_env()
270271
reg[[pkg_name]] <- ns_env

test_loadfast.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,33 @@ check("isNamespace() returns TRUE", quote(
169169
isNamespace(ns)
170170
))
171171

172+
check(".__DEVTOOLS__ marker is set (enables testthat mocking)", quote(
173+
!is.null(ns[[".__DEVTOOLS__"]])
174+
))
175+
176+
if (requireNamespace("pkgload", quietly = TRUE)) {
177+
check("pkgload::dev_meta() recognizes loadfast-loaded package", quote(
178+
!is.null(pkgload::dev_meta("devpackage"))
179+
))
180+
181+
check("with_mocked_bindings() auto-detects loadfast-loaded package", quote({
182+
result <- testthat::with_mocked_bindings(
183+
get("add", envir = asNamespace("devpackage"))(1, 2),
184+
add = function(a, b) 999L,
185+
.package = "devpackage"
186+
)
187+
result == 999L
188+
}))
189+
190+
check("with_mocked_bindings() without .package uses loadfast-loaded package", quote({
191+
result <- testthat::with_mocked_bindings(
192+
get("add", envir = asNamespace("devpackage"))(1, 2),
193+
add = function(a, b) 999L
194+
)
195+
result == 999L
196+
}))
197+
}
198+
172199
# --- Search path ---
173200
check("package:devpackage is on the search path", quote(
174201
"package:devpackage" %in% search()

0 commit comments

Comments
 (0)