Reads examples from Rd files and constructs testthat
-style tests.
testthat
expectations are built such that
Usage
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()
)
Arguments
- package
A package name whose examples should be tested
- path
Optionally, a path to a source code directory to use. Will only have an effect if parameter
package
is missing.- ...
Additional argument unused
- test_dir
An option directory where test files should be written. Defaults to a temporary directory.
- clean
Whether the
test_dir
should be removed upon completion of test execution. Defaults toTRUE
.- overwrite
Whether files should be overwritten if
test_dir
already exists. Defaults toTRUE
.- roxygenize
Whether R documentation files should be re-written using
roxygen2
prior to testing. When notFALSE
, tests written inroxygen2
tags will be used to update R documentation files prior to testing to use the most up-to-date example tests. May beTRUE
, or alist
of arguments passed toroxygen2::roxygenize
. By default, only enabled when running outside ofR CMD check
and while takingroxygen2
as a dependency.- reporter
A
testthat
reporter to use. Defaults to the active reporter in thetestthat
environment or default reporter.
Value
The result of testthat::source_file()
, after iterating over
generated test files.
Details
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.
Note
It is assumed that this function is used within a testthat
run, when
the necessary packages are already installed and loaded.
Examples
# \donttest{
# library(pkg.example)
path <- system.file("pkg.example", package = "testex")
test_examples_as_testthat(path = path)
#> Test passed 🎉
#> Test passed 🎉
#> Test passed 😀
#> Test passed 😸
#> Test passed 🥳
#> Test passed 😸
#> Test passed 🌈
#> Test passed 🥇
#> Test passed 😸
#> Test passed 😀
# }