vignettes/tests/test_util_spin.Rmd
test_util_spin.Rmd
library(testthat)
library(jeksterslabRutils)
context("Test util_spin.")
tmp_01 <- util_make_subdir()
tmp_02 <- util_make_subdir()
extdata
to temporary folder
extdata <- system.file(
"extdata",
"tests",
package = "jeksterslabRutils",
mustWork = TRUE
)
file_from <- file.path(
extdata,
"z_roxygen.R"
)
file <- file.path(
tmp_01,
"z_roxygen.R"
)
epub_from <- file.path(
extdata,
"valid.epub"
)
epub <- file.path(
tmp_01,
"valid.epub"
)
output <- file.path(
tmp_01,
"z_roxygen.Rmd"
)
file.copy(
from = c(
file_from,
epub_from
),
to = c(
file,
epub
)
)
#> [1] TRUE TRUE
html
is produced (dir
)
test_that("dir", {
if (file.exists(output)) {
unlink(output)
}
util_spin(
dir = tmp_01,
par = FALSE
)
expect_true(
file.exists(output)
)
})
#> Test passed 🎊
html
is produced (files
)
test_that("files", {
if (file.exists(output)) {
unlink(output)
}
util_spin(
files = file,
par = FALSE
)
expect_true(
file.exists(output)
)
})
#> Test passed 🥳
message <- "No files to spin"
files == 0
test_that("character(0)", {
expect_message(
util_spin(
files = character(0),
par = FALSE
),
regexp = message
)
})
#> Test passed 🌈
test_that("non-existent-file", {
expect_message(
util_spin(
files = "non-existent-file",
par = FALSE
),
regexp = message
)
})
#> Test passed 🥇
test_that("expect_warning", {
expect_warning(
util_spin(
files = epub,
par = FALSE
),
regexp = "Error spinning"
)
})
#> Test passed 🎊
R
or R Markdown
files in dir
.
test_that("expect_message", {
expect_message(
util_spin(
dir = tmp_02,
par = FALSE
),
regexp = message
)
})
#> Test passed 🥇
util_clean_dir(
dir = tmp_01,
create_dir = FALSE
)
util_clean_dir(
dir = tmp_02,
create_dir = FALSE
)