Skip to content

Commit

Permalink
Closes #446: Adding lifecycle_verbosity to tests of deprecated func…
Browse files Browse the repository at this point in the history
…tions (#447)

lifecycle_verbosity update
  • Loading branch information
ddsjoberg authored Apr 29, 2024
1 parent c90d460 commit 6bd237f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Suggests:
rmarkdown,
rstudioapi,
spelling,
testthat (>= 3.2.0)
testthat (>= 3.2.0),
withr
VignetteBuilder:
knitr
Config/testthat/edition: 3
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-compat_friendly_type.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# friendly_type_of ----
## Test 1: friendly_type_of() supports objects ----
test_that("friendly_type_of Test 1: friendly_type_of() supports objects", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_equal(friendly_type_of(mtcars), "a <data.frame> object")
expect_equal(friendly_type_of(quo(1)), "a <quosure> object")
})

## Test 2: friendly_type_of() supports matrices and arrays ----
test_that("friendly_type_of Test 2: friendly_type_of() supports matrices and arrays", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_equal(friendly_type_of(list()), "an empty list")
expect_equal(friendly_type_of(matrix(list(1, 2))), "a list matrix")
expect_equal(friendly_type_of(array(list(1, 2, 3), dim = 1:3)), "a list array")
Expand All @@ -20,6 +22,7 @@ test_that("friendly_type_of Test 2: friendly_type_of() supports matrices and arr

## Test 3: friendly_type_of() handles scalars ----
test_that("friendly_type_of Test 3: friendly_type_of() handles scalars", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_equal(friendly_type_of(NA), "`NA`")

expect_equal(friendly_type_of(TRUE), "`TRUE`")
Expand All @@ -41,6 +44,7 @@ test_that("friendly_type_of Test 3: friendly_type_of() handles scalars", {

## Test 4: friendly_type_of() edge cases ----
test_that("friendly_type_of Test 4: friendly_type_of() edge cases", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_equal(friendly_type_of(), "absent")
expect_equal(friendly_type_of(1:2, length = TRUE), "an integer vector of length 2")

Expand Down Expand Up @@ -77,6 +81,7 @@ test_that("friendly_type_of Test 4: friendly_type_of() edge cases", {
# .rlang_as_friendly_type ----
## Test 5: .rlang_as_friendly_type() works ----
test_that(".rlang_as_friendly_type Test 5: .rlang_as_friendly_type() works", {
withr::local_options(lifecycle_verbosity = "quiet")
setClass("person", slots = c(name = "character", age = "numeric"))
john <- new("person", name = "John", age = 18)
expect_equal(.rlang_as_friendly_type(typeof(john)), "an S4 object")
Expand All @@ -85,11 +90,13 @@ test_that(".rlang_as_friendly_type Test 5: .rlang_as_friendly_type() works", {
# .rlang_stop_unexpected_typeof ----
## Test 6: .rlang_stop_unexpected_typeof() works ----
test_that(".rlang_stop_unexpected_typeof Test 6: .rlang_stop_unexpected_typeof() works", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_error(.rlang_stop_unexpected_typeof("test"), "Unexpected type <character>.")
})

# stop_input_type ----
## Test 7: stop_input_type() works ----
test_that("stop_input_type Test 7: stop_input_type() works", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_error(stop_input_type(1, what = "character"))
})
1 change: 1 addition & 0 deletions tests/testthat/test-dev_utilities.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# arg_name ----
## Test 1: arg_name works ----
test_that("arg_name Test 1: arg_name works", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_equal(arg_name(sym("a")), "a")
expect_equal(arg_name(call("enquo", sym("a"))), "a")
expect_error(arg_name("a"), "Could not extract argument name from")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-quote.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# enumerate ----
## Test 1: enumerate works ----
test_that("enumerate Test 1: enumerate works", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_equal(enumerate(letters[1]), "`a`")
expect_equal(enumerate(letters[1:3]), "`a`, `b` and `c`")
expect_equal(enumerate(1:3, quote_fun = NULL), "1, 2 and 3")
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-what.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# what_is_it ----
## Test 1: atomic vectors of length 1 ----
test_that("what_is_it Test 1: atomic vectors of length 1", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_identical(what_is_it(NULL), "`NULL`")
expect_identical(what_is_it(TRUE), "`TRUE`")
expect_identical(what_is_it(NA), "`NA`")
Expand All @@ -12,6 +13,7 @@ test_that("what_is_it Test 1: atomic vectors of length 1", {

## Test 2: vectors ----
test_that("what_is_it Test 2: vectors", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_identical(what_is_it(letters), "a character vector")
expect_identical(what_is_it(1:10), "an integer vector")
expect_identical(what_is_it(c(1.2, 3)), "a double vector")
Expand All @@ -21,6 +23,7 @@ test_that("what_is_it Test 2: vectors", {

## Test 3: S3 objects ----
test_that("what_is_it Test 3: S3 objects", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_identical(what_is_it(mtcars), "a data frame")
expect_identical(what_is_it(factor(letters)), "a factor")
expect_identical(what_is_it(lm(hp ~ mpg, data = mtcars)), "an object of class 'lm'")
Expand All @@ -30,10 +33,12 @@ test_that("what_is_it Test 3: S3 objects", {

## Test 4: S4 objects ----
test_that("what_is_it Test 4: S4 objects", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_identical(what_is_it(lubridate::days(1)), "a S4 object of class 'Period'")
})

## Test 5: symbols ----
test_that("what_is_it Test 5: symbols", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_identical(what_is_it(quote(USUBJID)), "a symbol")
})

0 comments on commit 6bd237f

Please sign in to comment.