View source: R/run_covr_skip_nstf.R
| create_tinytest_coverage | R Documentation |
Instruments the package **namespace** with covr, runs all
tinytest files in inst/tinytest, and returns a covr coverage
object together with the tinytest results. This mirrors tinytest's execution
model (expectation helpers available; tests run from each file's directory)
while ensuring calls into the package namespace are traced.
create_tinytest_coverage(
pkg_source_path,
pkg_name,
tiny_dir = file.path(pkg_source_path, "inst", "tinytest"),
at_home = TRUE,
color = FALSE
)
pkg_source_path |
Character scalar. Path to the package source root. |
pkg_name |
Character scalar. Package name (as in |
tiny_dir |
Optional override for the tinytest directory. Defaults
to |
at_home |
Logical; passed to |
color |
Logical; color output from tinytest. Defaults to |
Intended for **source-tree** coverage of tinytest suites:
The package namespace is traced via covr::trace_environment()
so that calls made by tests to package functions are recorded
for coverage.
NOT_CRAN is set to "true" during the run (restored on exit)
so tinytest at_home() logic treats the run as local.
Environment-gated suites (e.g. Rcpp's RunAllRcppTests)
are enabled via prepare_tinytest_run_env() before the run and
restored on exit, so gated tests execute instead of exiting early.
Packages with headers in inst/include/ that self-compile during
tests receive dev-tree -I flags via
prepare_tinytest_dev_includes() (restored on exit).
Test files are driven by tinytest::run_test_dir() from
file.path(pkg_source_path, "inst", "tinytest"). A fatal
top-level error in a single file (e.g. a test that asserts the
installed package layout, which differs from a load_all source
tree) is caught so it does not discard coverage already recorded for
the files that ran.
Coverage is built from covr's counters using covr::as_coverage().
Objects that test files create in .GlobalEnv are removed on
exit. Some suites (e.g. Rcpp) call Rcpp::sourceCpp(),
whose env argument defaults to globalenv(), exporting
many compiled wrappers into the user's workspace. .GlobalEnv is
snapshotted before the run and only newly-added objects are removed
afterwards, so pre-existing objects are preserved.
Preconditions
The package under test should already be loaded (e.g.,
pkgload::load_all(pkg_source_path)), so that
asNamespace(pkg_name) exists and reflects the current source.
The directory inst/tinytest must exist and contain test files.
A list with components:
An object of class "coverage" (from covr).
The tinytests object returned by tinytest.
Other nstf_utility:
check_covr_skip_testit(),
create_base_tests_coverage(),
create_nstf_covr_list(),
get_nstf_test_path(),
get_source_test_mapping_nstf(),
prepare_tinytest_dev_includes(),
prepare_tinytest_run_env(),
restrict_test_paths_to_framework(),
run_covr_skip_nstf()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.