Skip to content

Commit f531c02

Browse files
committed
require non-empty strings for test description
1 parent 93b88db commit f531c02

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

NEWS.md

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

3+
* `test_that()` now emits an error if `expect_snapshot()` is invoked within
4+
a `test_that()` case with an empty description (#1980; @kevinushey).
5+
36
# testthat 3.2.1
47

58
* Fix incorrect format string detected by latest R-devel. Fix thanks to

R/snapshot-reporter.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SnapshotReporter <- R6::R6Class("SnapshotReporter",
4646
tolerance = testthat_tolerance(),
4747
variant = NULL,
4848
trace_env = NULL) {
49+
check_string(self$test, allow_empty = FALSE)
4950
i <- self$new_snaps$append(self$test, variant, save(value))
5051

5152
old_raw <- self$old_snaps$get(self$test, variant, i)

tests/testthat/test-snapshot.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,11 @@ test_that("hint is informative", {
162162
cat(snapshot_accept_hint("foo", "bar.R", reset_output = FALSE))
163163
})
164164
})
165+
166+
test_that("expect_snapshot requires a non-empty test label", {
167+
168+
test_that("", {
169+
expect_error(expect_snapshot(1 + 1))
170+
})
171+
172+
})

0 commit comments

Comments
 (0)