Skip to content

Commit

Permalink
feat: #466 inform function skeleton and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bms63 committed Nov 15, 2024
1 parent ead0e13 commit 03dc9a0
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
23 changes: 23 additions & 0 deletions R/lifecycle_admiral.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#' Deprecation with Soft Message
#'
#' Wrapper around `lifecycle::deprecate_soft()`
#'
#' @param ...
#'
#' @return Return value of the expression
#'
#' @keywords messages
#' @family messages
#'
#' @details
#'
#' @export
deprecate_inform <- function(...) {
tryCatch(
lifecycle::deprecate_soft(...),
warning = \(w) {
message(conditionMessage(w))
tryInvokeRestart("muffleWarning")
}
)
}
10 changes: 10 additions & 0 deletions tests/testthat/_snaps/lifecycle_admiral.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# lifecycle_admiral Test 1: Message is sent to user

Code
example_fun(data)

# lifecycle_admiral Test 2: Nicer message is sent to user

Code
example_fun(data)

44 changes: 44 additions & 0 deletions tests/testthat/test-lifecycle_admiral.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Test 1: Message is sent to user ----
test_that("lifecycle_admiral Test 1: Message is sent to user", {
example_fun <- function(dataset) {
deprecate_inform("1.0.0", "example_fun()", "example_fun2()")
assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID))
}

data <- dplyr::tribble(
~STUDYID, ~USUBJID,
"xyz", 123,
"xyz", 456
)

withr::local_options(lifecycle_verbosity = "quiet")
expect_snapshot(
example_fun(data),
)

})

## Test 2: Nicer message is sent to user ----
test_that("lifecycle_admiral Test 2: Nicer message is sent to user", {
example_fun <- function(dataset) {
deprecate_inform("1.0.0", "example_fun()", "example_fun2()",
details = c(
x = "Highly recommended to move to the suggested function",
i = "See admiral's deprecation guidance:
https://pharmaverse.github.io/admiraldev/dev/articles/programming_strategy.html#deprecation") #nolint
)
assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID))
}

data <- dplyr::tribble(
~STUDYID, ~USUBJID,
"xyz", 123,
"xyz", 456
)

withr::local_options(lifecycle_verbosity = "quiet")
expect_snapshot(
example_fun(data),
)

})

0 comments on commit 03dc9a0

Please sign in to comment.