testwhat icon indicating copy to clipboard operation
testwhat copied to clipboard

Document examples of checking for warnings or errors being thrown

Open richierocks opened this issue 6 years ago • 0 comments

It just took me a while to figure out the best way to test that a particular warning or error was thrown, so that means we need an example in the docs. (Same for other *what docs.)

I think that the best way is to use check_output(), including a Warning message: or Error: prefix.

Solution

warning("this is a warning")
stop("this is an error")

SCTs

ex() %>% check_output("Warning message: this is a warning", fixed = TRUE)
ex() %>% check_output("Error: this is an error", fixed = TRUE)

If you can distinguish output that went to stderr() rather than stdout(), you could maybe add an argument to check_output() to filter for just warnings and errors, but that may be overkill.

richierocks avatar Oct 16 '18 19:10 richierocks