Skip to content

Commit

Permalink
Merge pull request #133 from r-lib/warning-compat
Browse files Browse the repository at this point in the history
Restore previous footer behaviour
  • Loading branch information
lionel- authored Aug 22, 2022
2 parents 414dee1 + 917a13d commit f6d4645
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(cnd_footer,lifecycle_warning_deprecated)
S3method(print,lifecycle_warnings)
export(badge)
export(deprecate_soft)
export(deprecate_stop)
Expand Down
12 changes: 8 additions & 4 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,14 @@ deprecate_soft0 <- function(msg) {
}

deprecate_warn0 <- function(msg, trace = NULL, always = FALSE) {
footer <- paste_line(
if (!always) silver("This warning is displayed once every 8 hours."),
silver("Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.")
)
footer <- function(...) {
if (is_interactive()) {
c(
if (!always) silver("This warning is displayed once every 8 hours."),
silver("Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.")
)
}
}
wrn <- new_deprecated_warning(msg, trace, footer = footer)

# Record muffled warnings if testthat is running because it
Expand Down
14 changes: 9 additions & 5 deletions R/warning.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,28 @@
#' }
#' @export
last_lifecycle_warnings <- function() {
warnings_env$warnings
structure(
warnings_env$warnings,
class = c("lifecycle_warnings", "list")
)
}

new_deprecated_warning <- function(msg, trace, ...) {
new_deprecated_warning <- function(msg, trace, ..., footer = NULL) {
warning_cnd(
"lifecycle_warning_deprecated",
message = msg,
trace = trace,
footer = footer,
internal = list(...)
)
}

#' @export
cnd_footer.lifecycle_warning_deprecated <- function(cnd, ...) {
cnd$internal$footer
print.lifecycle_warnings <- function(x, ...) {
local_interactive(FALSE)
print(unclass(x))
}


warnings_env <- env(empty_env())

init_warnings <- function() {
Expand Down
4 changes: 0 additions & 4 deletions tests/testthat/_snaps/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
Condition
Warning:
`foo()` was deprecated in lifecycle 1.0.0.
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
Code
deprecate()

Expand All @@ -17,13 +15,11 @@
Condition
Warning:
`foo()` was deprecated in lifecycle 1.0.0.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
Code
deprecate(always = TRUE)
Condition
Warning:
`foo()` was deprecated in lifecycle 1.0.0.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.

# what deprecation messages are readable

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/_snaps/warning.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<warning/lifecycle_warning_deprecated>
Warning:
`trace()` was deprecated in lifecycle 1.0.0.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
---
Backtrace:
1. lifecycle::expect_deprecated(f())
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-lifecycle.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ test_that("soft-deprecation warnings are issued when called from child of global

test_that("deprecation warnings are not displayed again", {
local_options(lifecycle_verbosity = NULL)
local_interactive()

wrn <- catch_cnd(
deprecate_warn("1.0.0", "foo()", id = "once-every-8-hours-note"),
classes = "warning"
)
footer <- wrn$internal$footer
expect_true(is_string(footer) && grepl("once every 8 hours", footer))
footer <- cnd_footer(wrn)
expect_true(is_character(footer) && any(grepl("once every 8 hours", footer)))

local_options(lifecycle_verbosity = "warning")

Expand Down

0 comments on commit f6d4645

Please sign in to comment.