testthat testsReads examples from Rd files and constructs testthat-style tests.
testthat expectations are built such that
test_examples_as_testthat(
package,
path,
...,
test_dir = file.path(tempdir(), "testex-tests"),
clean = TRUE,
overwrite = TRUE,
roxygenize = !is_r_cmd_check() && uses_roxygen2(path),
reporter = testthat::get_reporter()
)The result of testthat::source_file(), after iterating over
generated test files.
A package name whose examples should be tested
Optionally, a path to a source code directory to use. Will only
have an effect if parameter package is missing.
Additional argument unused
An option directory where test files should be written. Defaults to a temporary directory.
Whether the test_dir should be removed upon completion of test
execution. Defaults to TRUE.
Whether files should be overwritten if test_dir already
exists. Defaults to TRUE.
Whether R documentation files should be re-written using
roxygen2 prior to testing. When not FALSE, tests written in roxygen2
tags will be used to update R documentation files prior to testing to use
the most up-to-date example tests. May be TRUE, or a list of arguments
passed to roxygen2::roxygenize. By default, only enabled when running
outside of R CMD check and while taking roxygen2 as a dependency.
A testthat reporter to use. Defaults to the active
reporter in the testthat environment or default reporter.
Each example expression is expected to run without error
Any testex expectations are expected to pass
Generally, you won't need to use this function directly. Instead, it
is called by a file generated by use_testex_as_testthat() which will add
any testex example tests to your existing testthat testing suite.
# \donttest{
# library(pkg.example)
path <- system.file("pkg.example", package = "testex")
test_examples_as_testthat(path = path)
# }
Run the code above in your browser using DataLab