From 956f4f6d6e2b9cb222a04b9b07088549366bc90b Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 29 Sep 2023 09:18:19 -0500 Subject: [PATCH] Advance deprecations (#1874) --- NAMESPACE | 1 - NEWS.md | 3 +++ R/deprec-condition.R | 22 +--------------------- R/test-files.R | 13 ++----------- tests/testthat/_snaps/deprec-condition.md | 8 ++++++++ tests/testthat/test-deprec-condition.R | 20 ++------------------ 6 files changed, 16 insertions(+), 51 deletions(-) create mode 100644 tests/testthat/_snaps/deprec-condition.md diff --git a/NAMESPACE b/NAMESPACE index 38580d203..e13d30231 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,7 +14,6 @@ S3method(format,expectation) S3method(format,expectation_success) S3method(format,mismatch_character) S3method(format,mismatch_numeric) -S3method(is_informative_error,default) S3method(output_replay,character) S3method(output_replay,error) S3method(output_replay,message) diff --git a/NEWS.md b/NEWS.md index 9485ea1c3..b623cca9a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # testthat (development version) +* `is_informative_error()` and the `wrap` argument to `test_dir()` and friends + are now defunct. + * `expect_snapshot_value()` has an improved error if the object can't be safely serialized using the specified `style` (#1771). diff --git a/R/deprec-condition.R b/R/deprec-condition.R index 4066f8047..74daf7253 100644 --- a/R/deprec-condition.R +++ b/R/deprec-condition.R @@ -141,25 +141,5 @@ get_messages <- function(x) { #' @keywords internal #' @export is_informative_error <- function(x, ...) { - lifecycle::deprecate_warn("3.0.0", "is_informative_error()") - ellipsis::check_dots_empty() - - if (!inherits(x, "error")) { - return(TRUE) - } - - if (inherits(x, c("simpleError", "Rcpp::eval_error", "Rcpp::exception"))) { - return(FALSE) - } - - if (inherits_only(x, c("rlang_error", "error", "condition"))) { - return(FALSE) - } - - UseMethod("is_informative_error") -} - -#' @export -is_informative_error.default <- function(x, ...) { - TRUE + lifecycle::deprecate_stop("3.0.0", "is_informative_error()") } diff --git a/R/test-files.R b/R/test-files.R index 0313caa7e..67afc1755 100644 --- a/R/test-files.R +++ b/R/test-files.R @@ -70,7 +70,7 @@ test_dir <- function(path, } if (!is_missing(wrap)) { - lifecycle::deprecate_warn("3.0.0", "test_dir(wrap = )") + lifecycle::deprecate_stop("3.0.0", "test_dir(wrap = )") } want_parallel <- find_parallel(path, load_package, package) @@ -94,7 +94,6 @@ test_dir <- function(path, env = env, stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning, - wrap = wrap, load_package = load_package, parallel = parallel ) @@ -150,11 +149,8 @@ test_files <- function(test_dir, parallel = FALSE, error_call = caller_env()) { - if (is_missing(wrap)) { - wrap <- TRUE - } if (!isTRUE(wrap)) { - lifecycle::deprecate_warn("3.0.0", "test_dir(wrap = )") + lifecycle::deprecate_stop("3.0.0", "test_dir(wrap = )") } # Must keep these two blocks in sync @@ -168,7 +164,6 @@ test_files <- function(test_dir, env = env, stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning, - wrap = wrap, load_package = load_package ) } else { @@ -182,7 +177,6 @@ test_files <- function(test_dir, stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning, desc = desc, - wrap = wrap, load_package = load_package, error_call = error_call ) @@ -216,7 +210,6 @@ test_files_serial <- function(test_dir, test_one_file, env = env, desc = desc, - wrap = wrap, error_call = error_call ) ) @@ -325,7 +318,6 @@ test_files_check <- function(results, stop_on_failure = TRUE, stop_on_warning = test_one_file <- function(path, env = test_env(), desc = NULL, - wrap = TRUE, error_call = caller_env()) { reporter <- get_reporter() on.exit(teardown_run(), add = TRUE) @@ -334,7 +326,6 @@ test_one_file <- function(path, source_file( path, env = env(env), - wrap = wrap, desc = desc, error_call = error_call ) diff --git a/tests/testthat/_snaps/deprec-condition.md b/tests/testthat/_snaps/deprec-condition.md new file mode 100644 index 000000000..e056791c7 --- /dev/null +++ b/tests/testthat/_snaps/deprec-condition.md @@ -0,0 +1,8 @@ +# is_informative_error is defunct + + Code + is_informative_error(TRUE) + Condition + Error: + ! `is_informative_error()` was deprecated in testthat 3.0.0 and is now defunct. + diff --git a/tests/testthat/test-deprec-condition.R b/tests/testthat/test-deprec-condition.R index 9c5cea0ba..76e76a618 100644 --- a/tests/testthat/test-deprec-condition.R +++ b/tests/testthat/test-deprec-condition.R @@ -1,21 +1,5 @@ -test_that("is_informative_error returns TRUE for basic errors", { - withr::local_options(lifecycle_verbosity = "quiet") - - is_informative <- function(x) is_informative_error(catch_cnd(x)) - - expect_false(is_informative(stop("!"))) - expect_false(is_informative(abort("!"))) - - expect_false(is_informative(abort("!", class = "Rcpp::eval_error"))) - expect_false(is_informative(abort("!", class = "Rcpp::exception"))) - - expect_true(is_informative(abort("!", class = "error_custom"))) - - with_bindings( - .env = global_env(), - is_informative_error.error_custom = function(...) FALSE, - expect_false(is_informative(abort("!", class = "error_custom"))) - ) +test_that("is_informative_error is defunct", { + expect_snapshot(is_informative_error(TRUE), error = TRUE) }) test_that("capture_warnings can ignore deprecation warnings", {