File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,14 @@ 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+
5462# ' Temporarily change the active testthat edition
5563# '
5664# ' `local_edition()` allows you to temporarily (within a single test or
@@ -62,7 +70,9 @@ edition_name <- function(x) {
6270# ' @param .env Environment that controls scope of changes. For expert use only.
6371# ' @keywords internal
6472local_edition <- function (x , .env = parent.frame()) {
65- stopifnot(is_zap(x ) || (is.numeric(x ) && length(x ) == 1 ))
73+ if (! is_valid_edition(x )) {
74+ stop(" Available editions are 2 and 3" , call. = FALSE )
75+ }
6676 old <- edition_set(x )
6777 withr :: defer(edition_set(old ), envir = .env )
6878}
Original file line number Diff line number Diff line change @@ -6,6 +6,17 @@ 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+ )
18+ })
19+
920test_that(" deprecation only fired for newer edition" , {
1021 local_edition(2 )
1122 expect_warning(edition_deprecate(3 , " old stuff" ), NA )
You can’t perform that action at this time.
0 commit comments