Learn R Programming

testthat (version 2.2.1)

verify_output: Verify output

Description

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.

Usage

verify_output(path, code, width = 80, crayon = FALSE)

Arguments

path

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

Code to execute.

width

Width of console output

crayon

Enable crayon package colouring?

CRAN

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.