Skip to content

Commit

Permalink
Advance deprecations (#1874)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Sep 29, 2023
1 parent dc9b381 commit 956f4f6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 51 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
22 changes: 1 addition & 21 deletions R/deprec-condition.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
}
13 changes: 2 additions & 11 deletions R/test-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
)
Expand Down Expand Up @@ -216,7 +210,6 @@ test_files_serial <- function(test_dir,
test_one_file,
env = env,
desc = desc,
wrap = wrap,
error_call = error_call
)
)
Expand Down Expand Up @@ -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)
Expand All @@ -334,7 +326,6 @@ test_one_file <- function(path,
source_file(
path,
env = env(env),
wrap = wrap,
desc = desc,
error_call = error_call
)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/deprec-condition.md
Original file line number Diff line number Diff line change
@@ -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.

20 changes: 2 additions & 18 deletions tests/testthat/test-deprec-condition.R
Original file line number Diff line number Diff line change
@@ -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", {
Expand Down

0 comments on commit 956f4f6

Please sign in to comment.