Skip to content

Commit

Permalink
Use doctest: add doctests for message functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hughjonesd committed Dec 13, 2022
1 parent 1c6400c commit a870ede
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -16,7 +16,7 @@ License: MIT + file LICENSE
Encoding: UTF-8 Encoding: UTF-8
Roxygen: list(markdown = TRUE, roclets = c("collate", "rd", "namespace", Roxygen: list(markdown = TRUE, roclets = c("collate", "rd", "namespace",
"doctest::dt_roclet")) "doctest::dt_roclet"))
RoxygenNote: 7.2.2 RoxygenNote: 7.2.3
Imports: Imports:
rappdirs, rappdirs,
filelock filelock
Expand Down
3 changes: 2 additions & 1 deletion R/messages.R
Expand Up @@ -18,6 +18,7 @@
#' id <- sample(10000L, 1) #' id <- sample(10000L, 1)
#' #'
#' for (n in 1:3) { #' for (n in 1:3) {
#' @expect warning(regexp = if (n == 1L) "once" else NA)
#' onetime_warning("will be shown once", id = id) #' onetime_warning("will be shown once", id = id)
#' } #' }
#' #'
Expand Down Expand Up @@ -109,7 +110,7 @@ onetime_startup_message <- function (...,
#' @doctest #' @doctest
#' oo <- options(onetime.dir = tempdir(check = TRUE)) #' oo <- options(onetime.dir = tempdir(check = TRUE))
#' id <- sample(10000L, 1L) #' id <- sample(10000L, 1L)
#' #' @expect message("A message")
#' onetime_message_confirm("A message to show one or more times", id = id) #' onetime_message_confirm("A message to show one or more times", id = id)
#' #'
#' onetime_reset(id = id) #' onetime_reset(id = id)
Expand Down
2 changes: 1 addition & 1 deletion R/meta.R
Expand Up @@ -39,7 +39,7 @@
#' Otherwise `FALSE`. #' Otherwise `FALSE`.
#' @export #' @export
#' #'
#' @doctest #' @examples
#' #'
#' check_ok_to_store() #' check_ok_to_store()
#' #'
Expand Down
1 change: 1 addition & 0 deletions R/rlang.R
Expand Up @@ -13,6 +13,7 @@
#' id <- sample(10000L, 1) #' id <- sample(10000L, 1)
#' #'
#' for (n in 1:3) { #' for (n in 1:3) {
#' @expect warning(regexp = if (n == 1L) "rlang" else NA)
#' onetime_rlang_warn(c("rlang-style warning", i = "Extra info"), id = id) #' onetime_rlang_warn(c("rlang-style warning", i = "Extra info"), id = id)
#' } #' }
#' #'
Expand Down
2 changes: 2 additions & 0 deletions man/check_ok_to_store.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions man/onetime.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/onetime_message_confirm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/testthat/test-doctest-onetime-rlang.R
@@ -0,0 +1,17 @@
# Generated by doctest: do not edit by hand
# Please edit file in R/rlang.R

test_that("Doctest: onetime-rlang", {
# Created from @doctest for `onetime-rlang`
# Source file: R/rlang.R
# Source line: 11
oo <- options(onetime.dir = tempdir(check = TRUE))
id <- sample(10000L, 1)
for (n in 1:3) {
expect_warning(onetime_rlang_warn(c("rlang-style warning", i = "Extra info"), id = id),
regexp = if (n == 1L) "rlang" else NA)
}
onetime_reset(id = id)
options(oo)
})

15 changes: 15 additions & 0 deletions tests/testthat/test-doctest-onetime_message_confirm.R
@@ -0,0 +1,15 @@
# Generated by doctest: do not edit by hand
# Please edit file in R/messages.R

test_that("Doctest: onetime_message_confirm", {
# Created from @doctest for `onetime_message_confirm`
# Source file: R/messages.R
# Source line: 110
oo <- options(onetime.dir = tempdir(check = TRUE))
id <- sample(10000L, 1L)
expect_message(onetime_message_confirm("A message to show one or more times", id = id),
"A message")
onetime_reset(id = id)
options(oo)
})

17 changes: 17 additions & 0 deletions tests/testthat/test-doctest-onetime_warning.R
@@ -0,0 +1,17 @@
# Generated by doctest: do not edit by hand
# Please edit file in R/messages.R

test_that("Doctest: onetime_warning", {
# Created from @doctest for `onetime_warning`
# Source file: R/messages.R
# Source line: 16
oo <- options(onetime.dir = tempdir(check = TRUE))
id <- sample(10000L, 1)
for (n in 1:3) {
expect_warning(onetime_warning("will be shown once", id = id), regexp = if (n ==
1L) "once" else NA)
}
onetime_reset(id = id)
options(oo)
})

0 comments on commit a870ede

Please sign in to comment.