tests/test_stopifnot.R

source("helper/helper.R")

expect_silent = function(x) {
  ok = try(eval.parent(substitute(x)), silent = TRUE)
  if (inherits(ok, "try-error"))
    stop(deparse(substitute(x)), " threw an error")
}

f = backports:::stopifnot
expect_error(f("Test" = 1 == 2), "Test")
expect_silent(f("Test" = 1 == 1))
expect_error(f("Test 1" = 1 == 2, "Test 2" = 2 == 2), "Test 1")
expect_error(f("Test 1" = 1 == 2, "Test 2" = 2 == 3), "Test 1")
expect_error(f("Test 1" = 1 == 1, "Test 2" = 2 == 3), "Test 2")
expect_silent(f("Test 1" = 1 == 1, "Test 2" = 2 == 2))

Try the backports package in your browser

Any scripts or data that you put into this service are public.

backports documentation built on Dec. 13, 2021, 5:08 p.m.