Skip to content

Commit c524d33

Browse files
committed
Merged origin/main into mcol-issue_1669
2 parents 5cf6fa4 + c7fedf4 commit c524d33

22 files changed

+91
-34
lines changed

β€ŽDESCRIPTIONβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ License: MIT + file LICENSE
1515
URL: https://testthat.r-lib.org, https://github.com/r-lib/testthat
1616
BugReports: https://github.com/r-lib/testthat/issues
1717
Depends:
18-
R (>= 3.6.0)
18+
R (>= 4.1.0)
1919
Imports:
2020
brio (>= 1.1.3),
2121
callr (>= 3.7.3),

β€ŽNAMESPACEβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export(skip_on_covr)
189189
export(skip_on_cran)
190190
export(skip_on_os)
191191
export(skip_on_travis)
192+
export(skip_unless_r)
192193
export(snapshot_accept)
193194
export(snapshot_review)
194195
export(source_dir)

β€ŽNEWS.mdβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# testthat (development version)
22

3+
* testthat now requires R 4.1.
4+
* `expect_s4_class()` now supports unquoting (@stibu81, #2064).
35
* `it()` now finds the correct evaluation environment in more cases (@averissimo, #2085).
46
* Fixed an issue preventing compilation from succeeding due to deprecation / removal of `std::uncaught_exception()` (@kevinushey, #2047).
57
* `snapshot_accept()` now works also when the tested file contains dots in the filename (@mcol, #1669).
8+
* New `skip_unless_r()` to skip running tests on unsuitable versions of R, e.g. `skip_unless_r(">= 4.1.0")` to skip tests that require, say, `...names` (@MichaelChirico, #2022)
69

710
# testthat 3.2.3
811

β€ŽR/expect-inheritance.Rβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ expect_s7_class <- function(object, class) {
125125
#' @rdname inheritance-expectations
126126
expect_s4_class <- function(object, class) {
127127
act <- quasi_label(enquo(object), arg = "object")
128-
act_val_lab <- format_class(methods::is(object))
128+
act$class <- format_class(methods::is(act$val))
129129
exp_lab <- format_class(class)
130130

131131
if (identical(class, NA)) {
@@ -139,7 +139,7 @@ expect_s4_class <- function(object, class) {
139139
} else {
140140
expect(
141141
methods::is(act$val, class),
142-
sprintf("%s inherits from %s not %s.", act$lab, act_val_lab, exp_lab)
142+
sprintf("%s inherits from %s not %s.", act$lab, act$class, exp_lab)
143143
)
144144
}
145145
} else {

β€ŽR/expect-self-test.Rβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ new_capture("expectation_success")
1919
#' Tools for testing expectations
2020
#'
2121
#' @description
22-
#' * `expect_sucess()` and `expect_failure()` check that there's at least
22+
#' * `expect_success()` and `expect_failure()` check that there's at least
2323
#' one success or failure respectively.
2424
#' * `expect_snapshot_failure()` records the failure message so that you can
2525
#' manually check that it is informative.
@@ -94,6 +94,9 @@ expect_no_failure <- function(expr) {
9494
expect_snapshot_skip <- function(x, cran = FALSE) {
9595
expect_snapshot_error(x, class = "skip", cran = cran)
9696
}
97+
expect_skip <- function(code) {
98+
expect_condition(code, class = "skip")
99+
}
97100
expect_no_skip <- function(code) {
98101
expect_no_condition(code, class = "skip")
99102
}

β€ŽR/skip.Rβ€Ž

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,30 @@ package_version <- function(x) {
126126
utils::packageVersion(x)
127127
}
128128

129+
#' @export
130+
#' @param spec A version specification like '>= 4.1.0' denoting that this test
131+
#' should only be run on R versions 4.1.0 and later.
132+
#' @rdname skip
133+
skip_unless_r <- function(spec) {
134+
parts <- unlist(strsplit(spec, " ", fixed = TRUE))
135+
if (length(parts) != 2L) {
136+
cli::cli_abort("{.arg spec} should be a comparison like '>=' and an R version separated by a space.")
137+
}
138+
comparator <- match.fun(parts[1L])
139+
required_version <- numeric_version(parts[2L])
140+
141+
current_version <- getRversion()
142+
skip_if_not(
143+
comparator(current_version, required_version),
144+
sprintf(
145+
"Current R version (%s) does not satisfy requirement (%s %s)",
146+
current_version, parts[1L], required_version
147+
)
148+
)
149+
}
150+
# for mocking
151+
getRversion <- NULL
152+
129153
#' @export
130154
#' @rdname skip
131155
skip_if_offline <- function(host = "captive.apple.com") {

β€ŽR/snapshot-cleanup.Rβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ snapshot_expected <- function(
6464
}
6565

6666
dir_contains <- function(paths, expected_files) {
67-
map_lgl(paths, ~ any(file.exists(file.path(.x, expected_files))))
67+
map_lgl(paths, \(path) any(file.exists(file.path(path, expected_files))))
6868
}

β€Žman/expect_success.Rdβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žman/skip.Rdβ€Ž

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žtests/testthat/_snaps/R4.0/snapshot-file/version.txtβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
Β (0)