EVOLUTION-MANAGER
Edit File: expect_no_error.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Does code run without error, warning, message, or other...</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for expect_no_error {testthat}"><tr><td>expect_no_error {testthat}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Does code run without error, warning, message, or other condition?</h2> <h3>Description</h3> <p><a href="https://lifecycle.r-lib.org/articles/stages.html#experimental"><img src="../help/figures/lifecycle-experimental.svg" alt='[Experimental]' /></a> </p> <p>These expectations are the opposite of <code><a href="expect_error.html">expect_error()</a></code>, <code>expect_warning()</code>, <code>expect_message()</code>, and <code>expect_condition()</code>. They assert the absence of an error, warning, or message, respectively. </p> <h3>Usage</h3> <pre> expect_no_error(object, ..., message = NULL, class = NULL) expect_no_warning(object, ..., message = NULL, class = NULL) expect_no_message(object, ..., message = NULL, class = NULL) expect_no_condition(object, ..., message = NULL, class = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>object</code></td> <td> <p>Object to test. </p> <p>Supports limited unquoting to make it easier to generate readable failures within a function or for loop. See <a href="quasi_label.html">quasi_label</a> for more details.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>These dots are for future extensions and must be empty.</p> </td></tr> <tr valign="top"><td><code>message, class</code></td> <td> <p>The default, <code style="white-space: pre;">message = NULL, class = NULL</code>, will fail if there is any error/warning/message/condition. </p> <p>If many cases, particularly when testing warnings and message, you will want to be more specific about the condition you are hoping <strong>not</strong> to see, i.e. the condition that motivated you to write the test. Similar to <code>expect_error()</code> and friends, you can specify the <code>message</code> (a regular expression that the message of the condition must match) and/or the <code>class</code> (a class the condition must inherit from). This ensures that the message/warnings you don't want never recur, while allowing new messages/warnings to bubble up for you to deal with. </p> <p>Note that you should only use <code>message</code> with errors/warnings/messages that you generate, or that base R generates (which tend to be stable). Avoid tests that rely on the specific text generated by another package since this can easily change. If you do need to test text generated by another package, either protect the test with <code>skip_on_cran()</code> or use <code>expect_snapshot()</code>.</p> </td></tr> </table> <h3>Examples</h3> <pre> expect_no_warning(1 + 1) foo <- function(x) { warning("This is a problem!") } # warning doesn't match so bubbles up: expect_no_warning(foo(), message = "bananas") # warning does match so causes a failure: try(expect_no_warning(foo(), message = "problem")) </pre> <hr /><div style="text-align: center;">[Package <em>testthat</em> version 3.1.5 <a href="00Index.html">Index</a>]</div> </body></html>