Skip to content

Commit 022b2e1

Browse files
authored
Return from snapshots, rather than skipping (#2175)
Because skipping causes the rest of the test not to run. I'm not sure what we should do instead, so I just return; this will still cause a skip to be emitted if no other expectations are run within the test. Fixes #1585
1 parent dd96289 commit 022b2e1

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# testthat (development version)
22

3+
* `expect_snapshot()` no longer skips on CRAN, as that skips the rest of the test. Instead it just returns, neither succeeding nor failing (#1585).
34
* Interrupting a test now prints the test name. This makes it easier to tell where a very slow test might be hanging (#1464)
45
* Parallel testthat now does not ignore test files with syntax errors (#1360).
56
* `expect_lt()`, `expect_gt()`, and friends have a refined display that is more likely to display the correct number of digits and shows you the actual values compared.

R/snapshot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ expect_snapshot_helper <- function(
313313
trace_env = caller_env()
314314
) {
315315
if (!cran && on_cran()) {
316-
skip("On CRAN")
316+
return(invisible())
317317
}
318318

319319
snapshotter <- get_snapshotter()

tests/testthat/test-snapshot.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,14 @@ test_that("expect_snapshot_warning validates its inputs", {
211211
expect_snapshot_warning(warning("!"), cran = "yes")
212212
})
213213
})
214+
215+
test_that("on CRAN, snapshots are not run but don't skill entire test", {
216+
local_on_cran(TRUE)
217+
218+
expectations <- capture_expectations(test_that("", {
219+
expect_snapshot(1 + 1)
220+
expect_true(TRUE)
221+
}))
222+
expect_length(expectations, 1)
223+
expect_s3_class(expectations[[1]], "expectation_success")
224+
})

0 commit comments

Comments
 (0)