Parameters

Initialize temporary folders in the working directory

tmp_01 <- util_make_subdir()
tmp_02 <- util_make_subdir()

Copy files from extdata to temporary folder

extdata <- system.file(
  "extdata",
  "tests",
  package = "jeksterslabRutils",
  mustWork = TRUE
)
file_from <- file.path(
  extdata,
  "z.Rmd"
)
file <- file.path(
  tmp_01,
  "z.Rmd"
)
epub_from <- file.path(
  extdata,
  "valid.epub"
)
epub <- file.path(
  tmp_01,
  "valid.epub"
)
output <- file.path(
  tmp_01,
  "z.html"
)
file.copy(
  from = c(
    file_from,
    epub_from
  ),
  to = c(
    file,
    epub
  )
)
#> [1] TRUE TRUE

Check if output html is produced (dir)

test_that("dir", {
  skip_on_appveyor()
  if (file.exists(output)) {
    unlink(output)
  }
  util_render(
    dir = tmp_01,
    par = FALSE
  )
  expect_true(
    file.exists(output)
  )
})
#> /usr/bin/pandoc +RTS -K512m -RTS z.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output z.html --lua-filter /home/jek/R/x86_64-pc-linux-gnu/4.0/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/jek/R/x86_64-pc-linux-gnu/4.0/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --standalone --section-divs --table-of-contents --toc-depth 3 --template /home/jek/R/x86_64-pc-linux-gnu/4.0/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable 'theme:bootstrap' --include-in-header /tmp/RtmpxhfsuK/rmarkdown-str355a645f28508.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' 
#> Test passed 🎊

Check if output html is produced (files)

test_that("files", {
  skip_on_appveyor()
  if (file.exists(output)) {
    unlink(output)
  }
  util_render(
    files = file,
    par = FALSE
  )
  expect_true(
    file.exists(output)
  )
})
#> /usr/bin/pandoc +RTS -K512m -RTS z.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output z.html --lua-filter /home/jek/R/x86_64-pc-linux-gnu/4.0/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/jek/R/x86_64-pc-linux-gnu/4.0/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --standalone --section-divs --table-of-contents --toc-depth 3 --template /home/jek/R/x86_64-pc-linux-gnu/4.0/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable 'theme:bootstrap' --include-in-header /tmp/RtmpxhfsuK/rmarkdown-str355a643e29fcf5.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' 
#> Test passed 🎊
message <- "No files to render"

Length of files == 0

test_that("character(0)", {
  expect_message(
    util_render(
      files = character(0),
      par = FALSE
    ),
    regexp = message
  )
})
#> Test passed 🥳

Non existent file

test_that("non-existent-file", {
  expect_message(
    util_render(
      files = "non-existent-file",
      par = FALSE
    ),
    regexp = message
  )
})
#> Test passed 🥇

Invalid file

test_that("expect_warning", {
  expect_warning(
    util_render(
      files = epub,
      par = FALSE
    ),
    regexp = "Error rendering"
  )
})
#> /usr/bin/pandoc +RTS -K512m -RTS valid.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output valid.html --lua-filter /home/jek/R/x86_64-pc-linux-gnu/4.0/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/jek/R/x86_64-pc-linux-gnu/4.0/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --standalone --section-divs --template /home/jek/R/x86_64-pc-linux-gnu/4.0/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable 'theme:bootstrap' --include-in-header /tmp/RtmpxhfsuK/rmarkdown-str355a646a2d9f22.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' 
#> Test passed 😸

No R or R Markdown files in dir.

test_that("expect_message", {
  expect_message(
    util_render(
      dir = tmp_02,
      par = FALSE
    ),
    regexp = message
  )
})
#> Test passed 🌈

Clean up temporary files and folders

util_clean_dir(
  dir = tmp_01,
  create_dir = FALSE
)
util_clean_dir(
  dir = tmp_02,
  create_dir = FALSE
)