diff --git a/DESCRIPTION b/DESCRIPTION index 150a46d8b..3c4ac2cfb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ License: MIT + file LICENSE URL: https://testthat.r-lib.org, https://github.com/r-lib/testthat BugReports: https://github.com/r-lib/testthat/issues Depends: - R (>= 3.6.0) + R (>= 4.1.0) Imports: brio (>= 1.1.3), callr (>= 3.7.3), diff --git a/NEWS.md b/NEWS.md index 60085f5fc..e19def1e4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # testthat (development version) +* 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). * Fixed an issue preventing compilation from succeeding due to deprecation / removal of `std::uncaught_exception()` (@kevinushey, #2047). diff --git a/R/snapshot-cleanup.R b/R/snapshot-cleanup.R index 3aedc2b76..2c2077c5a 100644 --- a/R/snapshot-cleanup.R +++ b/R/snapshot-cleanup.R @@ -64,5 +64,5 @@ snapshot_expected <- function( } dir_contains <- function(paths, expected_files) { - map_lgl(paths, ~ any(file.exists(file.path(.x, expected_files)))) + map_lgl(paths, \(path) any(file.exists(file.path(path, expected_files)))) } diff --git a/tests/testthat/_snaps/R4.0/snapshot-file/version.txt b/tests/testthat/_snaps/R4.0/snapshot-file/version.txt deleted file mode 100644 index 54df7d767..000000000 --- a/tests/testthat/_snaps/R4.0/snapshot-file/version.txt +++ /dev/null @@ -1 +0,0 @@ -R4.0 diff --git a/tests/testthat/_snaps/R4.0/snapshot.md b/tests/testthat/_snaps/R4.0/snapshot.md deleted file mode 100644 index 1ff946aae..000000000 --- a/tests/testthat/_snaps/R4.0/snapshot.md +++ /dev/null @@ -1,7 +0,0 @@ -# variants save different values - - Code - r_version() - Output - [1] "R4.0" - diff --git a/tests/testthat/test-expect-condition.R b/tests/testthat/test-expect-condition.R index 33e3d1711..858528819 100644 --- a/tests/testthat/test-expect-condition.R +++ b/tests/testthat/test-expect-condition.R @@ -78,7 +78,7 @@ test_that("can capture Throwable conditions from rJava", { test_that("capture correct trace_env (#1994)", { # This should fail, not error - expect_failure(expect_error(stop("oops")) %>% expect_warning()) + expect_failure(expect_error(stop("oops")) |> expect_warning()) expect_failure(expect_warning(expect_error(stop("oops")))) }) diff --git a/tests/testthat/test-expect-equality.R b/tests/testthat/test-expect-equality.R index 506cb8bc2..1650f1ef4 100644 --- a/tests/testthat/test-expect-equality.R +++ b/tests/testthat/test-expect-equality.R @@ -42,11 +42,8 @@ test_that("can control numeric tolerance", { expect_failure(expect_equal(x1, x2)) expect_success(expect_equal(x1, x2, tolerance = 1e-5)) expect_success(expect_equivalent(x1, x2, tolerance = 1e-5)) + # with partial matching - # we work around https://github.com/r-lib/testthat/issues/1188 - if (getRversion() < "3.6.0" && is.null(getOption("warnPartialMatchArgs"))) { - options(warnPartialMatchArgs = FALSE) - } withr::local_options(warnPartialMatchArgs = FALSE) expect_success(expect_equal(x1, x2, tol = 1e-5)) diff --git a/tests/testthat/test-expect-no-condition.R b/tests/testthat/test-expect-no-condition.R index cd66a5e12..22a59fbbc 100644 --- a/tests/testthat/test-expect-no-condition.R +++ b/tests/testthat/test-expect-no-condition.R @@ -27,8 +27,8 @@ test_that("expect_no_* don't emit success when they fail", { test_that("capture correct trace_env (#1994)", { # This should fail, not error - expect_failure(expect_message({message("a"); warn("b")}) %>% expect_no_warning()) - expect_failure(expect_no_message({message("a"); warn("b")}) %>% expect_warning()) + expect_failure(expect_message({message("a"); warn("b")}) |> expect_no_warning()) + expect_failure(expect_no_message({message("a"); warn("b")}) |> expect_warning()) }) test_that("unmatched conditions bubble up", { diff --git a/tests/testthat/test-snapshot-file.R b/tests/testthat/test-snapshot-file.R index eca4a1cb6..663192eb0 100644 --- a/tests/testthat/test-snapshot-file.R +++ b/tests/testthat/test-snapshot-file.R @@ -1,5 +1,4 @@ test_that("expect_snapshot_file works", { - skip_if_not(getRversion() >= "3.6.0") expect_snapshot_file( write_tmp_lines(letters), "foo.r", @@ -33,7 +32,6 @@ test_that("expect_snapshot_file works", { test_that("expect_snapshot_file works in a different directory", { - skip_if_not(getRversion() >= "3.6.0") path <- withr::local_tempdir() withr::local_dir(path) diff --git a/tests/testthat/test-snapshot-reporter.R b/tests/testthat/test-snapshot-reporter.R index ecbfaca33..1ff943af6 100644 --- a/tests/testthat/test-snapshot-reporter.R +++ b/tests/testthat/test-snapshot-reporter.R @@ -13,8 +13,8 @@ test_that("basic workflow", { snapper <- local_snapshotter(path) snapper$start_file("snapshot-2") # output if not active (because test not set here) - expect_snapshot_output("x") %>% - expect_message("Can't save") %>% + expect_snapshot_output("x") |> + expect_message("Can't save") |> expect_output("[1] \"x\"", fixed = TRUE) # warns on first creation diff --git a/tests/testthat/test-snapshot.R b/tests/testthat/test-snapshot.R index 5e514a112..cf19e464c 100644 --- a/tests/testthat/test-snapshot.R +++ b/tests/testthat/test-snapshot.R @@ -55,7 +55,7 @@ test_that("can scrub output/messages/warnings/errors", { expect_snapshot(secret(), transform = redact, error = TRUE) # Or with an inline fun - expect_snapshot(print("secret"), transform = ~ gsub("secret", "****", .x)) + expect_snapshot(print("secret"), transform = \(x) gsub("secret", "****", x)) }) test_that("always checks error status", { diff --git a/vignettes/custom-expectation.Rmd b/vignettes/custom-expectation.Rmd index be2c3234a..8bc1a4d7a 100644 --- a/vignettes/custom-expectation.Rmd +++ b/vignettes/custom-expectation.Rmd @@ -62,9 +62,9 @@ Next you call `expect()`. This has two arguments: Expectation functions are called primarily for their side-effects (triggering a failure), so should invisibly return their input, `act$val`. This allows expectations to be chained: ```{r} -mtcars %>% - expect_type("list") %>% - expect_s3_class("data.frame") %>% +mtcars |> + expect_type("list") |> + expect_s3_class("data.frame") |> expect_length(11) ``` diff --git a/vignettes/third-edition.Rmd b/vignettes/third-edition.Rmd index aae2ab9bc..da6b733ea 100644 --- a/vignettes/third-edition.Rmd +++ b/vignettes/third-edition.Rmd @@ -118,13 +118,13 @@ expect_warning(f(), "First") You can either add additional expectations to catch these warnings, or silence them all with `suppressWarnings()`: ```{r} -f() %>% - expect_warning("First") %>% - expect_warning("Second") %>% +f() |> + expect_warning("First") |> + expect_warning("Second") |> expect_warning("Third") -f() %>% - expect_warning("First") %>% +f() |> + expect_warning("First") |> suppressWarnings() ```