Skip to content

Commit e2aa4eb

Browse files
committed
Fix example; make CRAN behaviour consistent; early announce
1 parent f6d2949 commit e2aa4eb

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

R/snapshot-file.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#' ```R
5252
#' test_that("can save a file", {
5353
#' if (!can_save()) {
54-
#' announce_snapshot_file("data.txt")
54+
#' announce_snapshot_file(name = "data.txt")
5555
#' skip("Can't save file")
5656
#' }
5757
#' path <- withr::local_tempfile()
@@ -80,21 +80,20 @@
8080
#' }
8181
#'
8282
#' # You'd then also provide a helper that skips tests where you can't
83-
#' # be sure of producing exactly the same output
83+
#' # be sure of producing exactly the same output.
8484
#' expect_snapshot_plot <- function(name, code) {
85+
#' # Announce the file before touching skips or running `code`. This way,
86+
#' # if the skips are active, testthat will not auto-delete the corresponding
87+
#' # snapshot file.
88+
#' name <- paste0(name, ".png")
89+
#' announce_snapshot_file(name = name)
90+
#'
8591
#' # Other packages might affect results
8692
#' skip_if_not_installed("ggplot2", "2.0.0")
8793
#' # Or maybe the output is different on some operation systems
8894
#' skip_on_os("windows")
8995
#' # You'll need to carefully think about and experiment with these skips
9096
#'
91-
#' name <- paste0(name, ".png")
92-
#'
93-
#' # Announce the file before touching `code`. This way, if `code`
94-
#' # unexpectedly fails or skips, testthat will not auto-delete the
95-
#' # corresponding snapshot file.
96-
#' announce_snapshot_file(name = name)
97-
#'
9897
#' path <- save_png(code)
9998
#' expect_snapshot_file(path, name)
10099
#' }
@@ -110,14 +109,15 @@ expect_snapshot_file <- function(
110109
check_string(path)
111110
check_string(name)
112111
check_bool(cran)
112+
check_variant(variant)
113113

114114
edition_require(3, "expect_snapshot_file()")
115+
116+
announce_snapshot_file(name = name)
115117
if (!cran && on_cran()) {
116-
skip("On CRAN")
118+
return(invisible())
117119
}
118120

119-
check_variant(variant)
120-
121121
snapshotter <- get_snapshotter()
122122
if (is.null(snapshotter)) {
123123
snapshot_not_available(path)

man/expect_snapshot_file.Rd

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)