Skip to content
Open
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
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ Imports:
cli (>= 3.4.0),
rlang (>= 1.1.0)
Suggests:
covr,
knitr,
lintr (>= 3.1.0),
rmarkdown,
testthat (>= 3.0.1),
testthat (>= 3.2.1),
tibble,
tidyverse,
tools,
Expand Down
2 changes: 1 addition & 1 deletion R/deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ lifecycle_message <- function(
msg <- lifecycle_message_what(what, when)

if (!is_null(with)) {
with <- spec(with, NULL, signaller = signaller)
with <- spec(with, NULL, signaller = signaller, type = "with")
msg <- c(msg, "i" = lifecycle_message_with(with, what))
}

Expand Down
9 changes: 5 additions & 4 deletions R/spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ spec <- function(
spec,
env = caller_env(),
signaller = "signal_lifecycle",
type = c("what", "with"),
error_call = caller_env()
) {
ctxt <- list(
Expand All @@ -18,7 +19,7 @@ spec <- function(
from = signaller
)
} else {
what <- parse_what(spec, ctxt = ctxt)
what <- parse_what(spec, ctxt = ctxt, type = type)

list(
fn = spec_fn(what$call, ctxt = ctxt),
Expand All @@ -30,16 +31,16 @@ spec <- function(
}
}

parse_what <- function(what, ctxt) {
parse_what <- function(what, ctxt, type = c("what", "with")) {
check_string(what, call = ctxt$call)

type <- arg_match(type)
call <- parse_expr(what)

if (!is_call(call)) {
what <- as_string(what)
cli::cli_abort(
c(
"{.arg what} must have function call syntax.",
"{.arg {type}} must have function call syntax.",
"",
" " = "# Good:",
" " = "{ ctxt$signaller }(\"{what}()\")",
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/_snaps/deprecate.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,17 @@
Error:
! `id` must be a single string, not the number 1.

# deprecate_soft() mentions the correct argument (#152)

Code
deprecate_warn(when = "1.0.0", what = "foo()", with = "bar")
Condition
Error in `lifecycle_message()`:
! `with` must have function call syntax.

# Good:
deprecate_warn("bar()")

# Bad:
deprecate_warn("bar")

4 changes: 0 additions & 4 deletions tests/testthat/helper-lifecycle.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ expect_lifecycle_defunct <- function(object, ...) {
expect_error(object, class = "defunctError")
}

expect_no_warning <- function(...) {
expect_warning(regexp = NA, ...)
}

try2 <- function(expr) {
cat(paste0("\n", as_label2(substitute(expr)), ":\n\n"))
cat(catch_cnd(expr, classes = "error")$message, "\n\n")
Expand Down
16 changes: 11 additions & 5 deletions tests/testthat/test-deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ test_that("default deprecations behave as expected", {
expect_snapshot({
(expect_warning(direct(), class = "lifecycle_warning_deprecated"))
})
expect_warning(indirect(), NA)
expect_warning(indirect(), NA)
expect_no_warning(indirect())
expect_no_warning(indirect())

expect_snapshot({
(expect_defunct(deprecate_stop("1.0.0", "foo()")))
Expand Down Expand Up @@ -66,8 +66,8 @@ test_that("indirect usage recommends contacting authors", {
test_that("quiet suppresses _soft and _warn", {
local_options(lifecycle_verbosity = "quiet")

expect_warning(deprecate_soft("1.0.0", "foo()"), NA)
expect_warning(deprecate_warn("1.0.0", "foo()"), NA)
expect_no_warning(deprecate_soft("1.0.0", "foo()"))
expect_no_warning(deprecate_warn("1.0.0", "foo()"))
expect_defunct(deprecate_stop("1.0.0", "foo()"))
})

Expand Down Expand Up @@ -108,7 +108,7 @@ test_that("soft deprecation uses correct calling envs", {

# Calling package function indirectly from global env shouldn't
cnd <- catch_cnd(evalq(softly_softly(), global_env()), "warning")
expect_equal(cnd, NULL)
expect_null(cnd)
})

test_that("warning conditions are signaled only once if warnings are suppressed", {
Expand Down Expand Up @@ -266,3 +266,9 @@ test_that("needs_warning works as expected", {
env_poke(deprecation_env, "test", TRUE)
expect_false(needs_warning("test"))
})

test_that("deprecate_soft() mentions the correct argument (#152)", {
expect_snapshot(error = TRUE, {
deprecate_warn(when = "1.0.0", what = "foo()", with = "bar")
})
})