Skip to content

Commit

Permalink
require non-empty strings for test description (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey authored Oct 29, 2024
1 parent c843a3b commit 3628792
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# testthat (development version)

* `expect_snapshot()` now errors when called from a `test_that()` that has an empty description (@kevinushey, #1980).
* `skip_if_not_installed()` produces a clearer message (@MichaelChirico, #1959).
* `with_mock()` and `local_mock()` have been unconditionally deprecated as they will no longer work in future versions of R (#1999).
* `expect_condition()` and friends now include the `class` of the expected condition in the failure mesage, if used (#1987).
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 @@ -167,3 +167,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))
})

})

0 comments on commit 3628792

Please sign in to comment.