Debian Codegraph @

tests/testthat/helpers.R

raw
1 local_rmd_file <- function(..., .env = parent.frame()) {
2 path <- withr::local_tempfile(.local_envir = .env, fileext = ".Rmd")
3 xfun::write_utf8(c(...), path)
4 path
5 }
6
7 .render_and_read <- function(input, ...) {
8 skip_if_not_pandoc()
9 output_file <- withr::local_tempfile()
10 res <- rmarkdown::render(input, output_file = output_file, quiet = TRUE, ...)
11 xfun::read_utf8(res)
12 }
13
14 # Use to test pandoc availability or version lower than
15 skip_if_not_pandoc <- function(ver = NULL) {
16 if (!pandoc_available(ver)) {
17 msg <- if (is.null(ver)) {
18 "Pandoc is not available"
19 } else {
20 sprintf("Version of Pandoc is lower than %s.", ver)
21 }
22 skip(msg)
23 }
24 }
25
26 # Use to test version greater than
27 skip_if_pandoc <- function(ver = NULL) {
28 if (pandoc_available(ver)) {
29 msg <- if (is.null(ver)) {
30 "Pandoc is available"
31 } else {
32 sprintf("Version of Pandoc is greater than %s.", ver)
33 }
34 skip(msg)
35 }
36 }
37