This is a regression test records interwoven code and output into a file, similar to Rmd. It's 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, there's no way to test that automatically, so the best we can do is make the results explicit by saving to a text file. This makes the presentation easier to see in code reviews, and avoids changing it accidentally.

verify_output(path, code, width = 80, crayon = FALSE,
  unicode = FALSE, env = caller_env())



Path to save file. Typically this will be a call to test_path() so that the same path when the code is run interactively.


Code to execute.


Width of console output


Enable crayon package colouring?


Enable cli package UTF-8 symbols? If you set this to TRUE, call skip_if(!cli::is_utf8_output()) to disable the test on your CI platforms that don't support UTF-8 (e.g. Windows).


The environment to evaluate code in.


  • Strings appear as R comments in the output.

  • Strings starting with # appear as headers in the output.


On CRAN, verify_output() will not fail if the output changes. This is beause 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 presentation.

Differences to Rmd

verify_output() can only capture the abstract syntax tree, losing all whitespace and comments. To mildy offset this limitation, bare string are turned into comments.