Skip to content

Commit 5f394fb

Browse files
committed
Refactor path discovery
1 parent d214082 commit 5f394fb

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

R/snapshot.R

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,9 @@ snapshot_hint <- function(
399399
id <- c(file, if (!identical(variant, "_default")) variant, name)
400400
full_name <- paste0(id, collapse = "/")
401401

402-
args <- encodeString(full_name, quote = '"')
403-
# Include path argument if we're in a different working directory
404-
wd <- Sys.getenv("TESTTHAT_WD", unset = "")
405-
if (wd != "") {
406-
test_path <- file.path(wd, "tests/testthat")
407-
if (test_path != getwd()) {
408-
args <- paste0(args, ", ", encodeString(getwd(), quote = '"'))
409-
}
410-
}
402+
args <- c(full_name, snapshot_hint_path())
403+
args <- encodeString(args, quote = '"')
404+
args <- paste0(args, collapse = ", ")
411405

412406
accept_link <- cli::format_inline("{.run testthat::snapshot_accept({args})}")
413407
review_link <- cli::format_inline("{.run testthat::snapshot_review({args})}")
@@ -419,6 +413,21 @@ snapshot_hint <- function(
419413
structure(out, class = "testthat_hint")
420414
}
421415

416+
# Include path argument if we're in a different working directory
417+
snapshot_hint_path <- function() {
418+
wd <- Sys.getenv("TESTTHAT_WD", unset = "")
419+
if (wd == "") {
420+
return()
421+
}
422+
423+
test_path <- file.path(wd, "tests/testthat")
424+
if (test_path == getwd()) {
425+
return()
426+
}
427+
428+
getwd()
429+
}
430+
422431
#' @export
423432
print.testthat_hint <- function(x, ...) {
424433
cat(paste0(x, "\n", collapse = ""))

0 commit comments

Comments
 (0)