File tree Expand file tree Collapse file tree 4 files changed +22
-22
lines changed Expand file tree Collapse file tree 4 files changed +22
-22
lines changed Original file line number Diff line number Diff line change 11# testthat (development version)
22
3+ * ` local_edition() ` now gives a useful error for bad values (#1547 ).
34* testthat now requires R 4.1.
45* ` expect_s4_class() ` now supports unquoting (@stibu81 , #2064 ).
56* ` it() ` now finds the correct evaluation environment in more cases (@averissimo , #2085 ).
Original file line number Diff line number Diff line change @@ -51,14 +51,6 @@ edition_name <- function(x) {
5151 }
5252}
5353
54- is_valid_edition <- function (x ) {
55- if (is_zap(x )) {
56- TRUE
57- } else {
58- is.numeric(x ) && length(x ) == 1 && x %in% c(2 , 3 )
59- }
60- }
61-
6254# ' Temporarily change the active testthat edition
6355# '
6456# ' `local_edition()` allows you to temporarily (within a single test or
@@ -69,10 +61,7 @@ is_valid_edition <- function(x) {
6961# ' @param x Edition Should be a single integer.
7062# ' @param .env Environment that controls scope of changes. For expert use only.
7163local_edition <- function (x , .env = parent.frame()) {
72- if (! is_valid_edition(x )) {
73- stop(" Available editions are 2 and 3" , call. = FALSE )
74- }
75-
64+ check_number_whole(x , min = 2 , max = 3 )
7665 local_bindings(edition = x , .env = the , .frame = .env )
7766}
7867
Original file line number Diff line number Diff line change 1+ # checks its inputs
2+
3+ Code
4+ local_edition("x")
5+ Condition
6+ Error in `local_edition()`:
7+ ! `x` must be a whole number, not the string "x".
8+ Code
9+ local_edition(5)
10+ Condition
11+ Error in `local_edition()`:
12+ ! `x` must be a whole number between 2 and 3, not the number 5.
13+
114# deprecation only fired for newer edition
215
316 Code
Original file line number Diff line number Diff line change @@ -6,15 +6,11 @@ test_that("can locally override edition", {
66 expect_equal(edition_get(), 2 )
77})
88
9- test_that(" only existing editions can be set" , {
10- expect_error(
11- local_edition(5 ),
12- regexp = " Available editions are 2 and 3"
13- )
14- expect_error(
15- local_edition(- 1 ),
16- regexp = " Available editions are 2 and 3"
17- )
9+ test_that(" checks its inputs" , {
10+ expect_snapshot(error = TRUE , {
11+ local_edition(" x" )
12+ local_edition(5 )
13+ })
1814})
1915
2016test_that(" deprecation only fired for newer edition" , {
@@ -45,7 +41,8 @@ test_that("edition for non-package dir is 2", {
4541})
4642
4743test_that(" can set the edition via an environment variable" , {
48- local_edition(zap())
44+ local_bindings(edition = zap(), .env = the )
45+
4946 withr :: local_envvar(TESTTHAT_EDITION = 2 )
5047 expect_equal(edition_get(), 2 )
5148
You can’t perform that action at this time.
0 commit comments