report_side_effects: Report side effects for expressions in test files

View source: R/expectations.R

report_side_effectsR Documentation

Report side effects for expressions in test files

Description

Call this function from within a test file to report side effects.

Usage

report_side_effects(
  report = TRUE,
  envvar = report,
  pwd = report,
  files = report,
  locale = report
)

Arguments

report

[logical] report all side-effects

envvar

[logical] changes in environment variables

pwd

[logical] changes in working directory

files

[logical] changes in files in the directory where the test file lives. Also watches subdirectories.

locale

[logical] Changes in locale settings as detected by link[base]{Sys.getlocale} are reported.

Value

A named logical, indicating which aspects of the environment are tracked, invisibly.

Details

A side effect causes a change in an external variable outside of the scope of a function, or test file. This includes environment variables, global options, global R variables, creating files or directories, and so on.

If this function is called in a test file, side effects are monitored from that point in the file and only for that file. The state of the environment before and after running every expression in the file are compared.

There is some performance penalty in tracking external variables, especially for those that require a system call.

Note

There could be side-effects that are untrackable by tinytest. This includes packages that use a global internal state within their namespace or packages that use a global state within compiled code.

Examples

# switch on
report_side_effects()
# switch off
report_side_effects(FALSE)

# only report changes in environment variables
report_side_effects(report=FALSE, envvar=TRUE)


tinytest documentation built on March 7, 2023, 7:43 p.m.