Skip to content

Commit

Permalink
Make links to snapshot_review() clickable
Browse files Browse the repository at this point in the history
Fixes #1821
  • Loading branch information
hadley committed Sep 26, 2023
1 parent 97887bc commit ddf9ff1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# testthat (development version)

* `expect_snapshot_file()` now generates clickable links to review changes
(#1821).

* `options(rlang_interactive = TRUE)` no longer causes `skip_on_cran()` to
not run on CRAN (#1868).

Expand Down
13 changes: 11 additions & 2 deletions R/snapshot-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,24 @@ announce_snapshot_file <- function(path, name = basename(path)) {
}
}

snapshot_review_hint <- function(test, name, ci = on_ci(), check = in_rcmd_check()) {
snapshot_review_hint <- function(test,
name,
ci = on_ci(),
check = in_rcmd_check(),
reset_output = TRUE) {
if (reset_output) {
local_reporter_output()
}


path <- paste0("tests/testthat/_snaps/", test, "/", new_name(name))

paste0(
if (check && ci) "* Download and unzip run artifact\n",
if (check && !ci) "* Locate check directory\n",
if (check) paste0("* Copy '", path, "' to local test directory\n"),
if (check) "* ",
paste0("Run `testthat::snapshot_review('", test, "/')` to review changes")
cli::format_inline("Run {.run testthat::snapshot_review('{test}/')} to review changes")
)
}

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-snapshot-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ test_that("split_path handles edge cases", {
})

test_that("snapshot_hint output differs in R CMD check", {
snapshot_review_hint <- function(...) {
testthat:::snapshot_review_hint(..., reset_output = FALSE)
}

expect_snapshot(cat(snapshot_review_hint("lala", "foo.r", check = FALSE, ci = FALSE)))
expect_snapshot(cat(snapshot_review_hint("lala", "foo.r", check = TRUE, ci = FALSE)))
expect_snapshot(cat(snapshot_review_hint("lala", "foo.r", check = TRUE, ci = TRUE)))
Expand Down

0 comments on commit ddf9ff1

Please sign in to comment.