Skip to content
Merged
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
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)

* `local_edition()` now gives a useful error for bad values (#1547).
* testthat now requires R 4.1.
* `expect_s4_class()` now supports unquoting (@stibu81, #2064).
* `it()` now finds the correct evaluation environment in more cases (@averissimo, #2085).
Expand Down
3 changes: 1 addition & 2 deletions R/edition.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ edition_name <- function(x) {
#' @param x Edition Should be a single integer.
#' @param .env Environment that controls scope of changes. For expert use only.
local_edition <- function(x, .env = parent.frame()) {
stopifnot(is_zap(x) || (is.numeric(x) && length(x) == 1))

check_number_whole(x, min = 2, max = 3)
local_bindings(edition = x, .env = the, .frame = .env)
}

Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/_snaps/edition.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# checks its inputs

Code
local_edition("x")
Condition
Error in `local_edition()`:
! `x` must be a whole number, not the string "x".
Code
local_edition(5)
Condition
Error in `local_edition()`:
! `x` must be a whole number between 2 and 3, not the number 5.

# deprecation only fired for newer edition

Code
Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/test-edition.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ test_that("can locally override edition", {
expect_equal(edition_get(), 2)
})

test_that("checks its inputs", {
expect_snapshot(error = TRUE, {
local_edition("x")
local_edition(5)
})
})

test_that("deprecation only fired for newer edition", {
local_edition(2)
expect_warning(edition_deprecate(3, "old stuff"), NA)
Expand Down Expand Up @@ -34,7 +41,8 @@ test_that("edition for non-package dir is 2", {
})

test_that("can set the edition via an environment variable", {
local_edition(zap())
local_bindings(edition = zap(), .env = the)

withr::local_envvar(TESTTHAT_EDITION = 2)
expect_equal(edition_get(), 2)

Expand Down
Loading