Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually remove variant snapshot error display #1857

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# testthat (development version)

* All packages, regardless of whether or not they use rlang 1.0.0, now
use the new snapshot display for errors, warnings, and messages (#1856).

* testthat uses an improved algorithm for finding the srcref associated with
an expectation/error/warning/skip. It now looks for the most recent call
that has known source and is found inside the `test_that()` call. This
Expand Down Expand Up @@ -52,9 +55,6 @@

* `teardown_env()` works in more cases.

* All packages, regardless of whether or not they use rlang, now
use the new snapshot display for errors, warnings, and messages.

* testthat no longer truncates tracebacks and uses rlang's default tree
display.

Expand Down
5 changes: 0 additions & 5 deletions R/edition.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,3 @@ find_dep_version <- function(name, path, package = NULL) {
has_dep <- function(name, path, package = NULL) {
!is.null(find_dep_version(name, path, package = package))
}

use_rlang_1_0 <- function() {
rlang::is_true(peek_option("testthat:::rlang_dep")) &&
is_installed("rlang", version = "0.99.0.9001")
}
28 changes: 0 additions & 28 deletions R/snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ snapshot_replay.condition <- function(x,
...,
transform = NULL,
cnd_class = FALSE) {
if (!use_rlang_1_0()) {
return(snapshot_replay_condition_legacy(
x,
state,
transform = transform
))
}

cnd_message <- env_get(ns_env("rlang"), "cnd_message")

Expand All @@ -153,27 +146,6 @@ snapshot_replay.condition <- function(x,
c(snap_header(state, type), snapshot_lines(msg, transform))
}

snapshot_replay_condition_legacy <- function(x, state = env(), transform = NULL) {
msg <- cnd_message(x)

if (inherits(x, "error")) {
state$error <- x
type <- "Error"
msg <- add_implicit_nl(msg)
} else if (inherits(x, "warning")) {
type <- "Warning"
msg <- paste0(msg, "\n")
} else if (inherits(x, "message")) {
type <- "Message"
} else {
type <- "Condition"
}

class <- paste0(type, " <", class(x)[[1]], ">")

c(snap_header(state, class), snapshot_lines(msg, transform))
}

snapshot_lines <- function(x, transform = NULL) {
x <- split_lines(x)
if (!is.null(transform)) {
Expand Down
46 changes: 0 additions & 46 deletions tests/testthat/_snaps/rlang-1.0/snapshot.md

This file was deleted.

39 changes: 0 additions & 39 deletions tests/testthat/_snaps/rlang-pre-1.0/snapshot.md

This file was deleted.

46 changes: 46 additions & 0 deletions tests/testthat/_snaps/snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,52 @@
x <- quote(!!foo)
expect_equal(x, call("!", call("!", quote(foo))))

# full condition message is printed with rlang

Code
foo <- error_cnd("foo", message = "Title parent.")
abort("Title.", parent = foo)
Condition
Error:
! Title.
Caused by error:
! Title parent.

# can print with and without condition classes

Code
f()
Message <simpleMessage>
foo
Condition <simpleWarning>
Warning in `f()`:
bar
Condition <simpleError>
Error in `f()`:
! baz

---

Code
f()
Message
foo
Condition
Warning in `f()`:
bar
Error in `f()`:
! baz

# errors and warnings are folded

Code
f()
Condition
Warning in `f()`:
foo
Error in `f()`:
! bar

# hint is informative

Code
Expand Down
7 changes: 0 additions & 7 deletions tests/testthat/helper-testthat.R

This file was deleted.

38 changes: 7 additions & 31 deletions tests/testthat/test-snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,52 +145,28 @@ test_that("`expect_snapshot()` does not inject", {
})

test_that("full condition message is printed with rlang", {
local_use_rlang_1_0()

expect_snapshot(
error = TRUE,
variant = rlang_version(),
{
foo <- error_cnd("foo", message = "Title parent.")
abort("Title.", parent = foo)
}
)
expect_snapshot(error = TRUE, {
foo <- error_cnd("foo", message = "Title parent.")
abort("Title.", parent = foo)
})
})

test_that("can print with and without condition classes", {
local_use_rlang_1_0()

f <- function() {
message("foo")
warning("bar")
stop("baz")
}
expect_snapshot(
error = TRUE,
cnd_class = TRUE,
variant = rlang_version(),
f()
)
expect_snapshot(
error = TRUE,
cnd_class = FALSE,
variant = rlang_version(),
f()
)
expect_snapshot(error = TRUE, cnd_class = TRUE, f())
expect_snapshot(error = TRUE, cnd_class = FALSE, f())
})

test_that("errors and warnings are folded", {
local_use_rlang_1_0()

f <- function() {
warning("foo")
stop("bar")
}
expect_snapshot(
error = TRUE,
variant = rlang_version(),
f()
)
expect_snapshot(error = TRUE, f())
})

test_that("hint is informative", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-test-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ test_that("can configure `load_all()` (#1636)", {
})

test_that("helpers are included in the testing environment", {
expect_true("rlang_version" %in% names(the$testing_env))
expect_true("abcdefghi" %in% names(the$testing_env))
})