Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require non-empty strings for test description #1981

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

* `test_that()` now emits an error if `expect_snapshot()` is invoked within
a `test_that()` case with an empty description (#1980; @kevinushey).

# testthat 3.2.1

* Fix incorrect format string detected by latest R-devel. Fix thanks to
Expand Down
1 change: 1 addition & 0 deletions R/snapshot-reporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ SnapshotReporter <- R6::R6Class("SnapshotReporter",
tolerance = testthat_tolerance(),
variant = NULL,
trace_env = NULL) {
check_string(self$test, allow_empty = FALSE)
i <- self$new_snaps$append(self$test, variant, save(value))

old_raw <- self$old_snaps$get(self$test, variant, i)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@ test_that("hint is informative", {
cat(snapshot_accept_hint("foo", "bar.R", reset_output = FALSE))
})
})

test_that("expect_snapshot requires a non-empty test label", {

test_that("", {
expect_error(expect_snapshot(1 + 1))
})

})
Loading