This function is superseded in favour of
expect_snapshot() and friends.
This is a regression test that records interwoven code and output into a
file, in a similar way to knitting an
.Rmd file (but see caveats below).
verify_output() is designed particularly for testing print methods and error
messages, where the primary goal is to ensure that the output is helpful to
a human. Obviously, you can't test that with code, so the best you can do is
make the results explicit by saving them to a text file. This makes the output
easy to verify in code reviews, and ensures that you don't change the output
verify_output() is designed to be used with git: to see what has changed
from the previous run, you'll need to use
git diff or similar.
verify_output( path, code, width = 80, crayon = FALSE, unicode = FALSE, env = caller_env() )
Path to record results.
This should usually be a call to
Width of console output
Enable crayon package colouring?
Enable cli package UTF-8 symbols? If you set this to
The environment to evaluate
verify_output() can only capture the abstract syntax tree, losing all
whitespace and comments. To mildly offset this limitation:
Strings are converted to R comments in the output.
Strings starting with
# are converted to headers in the output.
verify_output() will never fail, even if the output changes.
This avoids false positives because tests of print methods and error
messages are often fragile due to implicit dependencies on other packages,
and failure does not imply incorrect computation, just a change in