tests/testthat/test-errorHandling.R

context("errorHandling")

test_that("stopOnError() is silent when there is no error", {
  # setup
  myFunc <- function(x) {
    a <- log(x)
  }
  result <- try({
    myFunc(10)
  }, silent=TRUE)
  
  expect_silent(stopOnError(result))
  expect_silent(stopOnError(result,"custom error message"))
  
})

test_that("stopOnError() converts error messages", {
  # setup
  myFunc <- function(x) {
    a <- log(x)
  }
  result <- try({
    myFunc("ten")
  }, silent=TRUE)
  
  expect_error(stopOnError(result))
  expect_error(stopOnError(result,"custom error message"),
               "custom error message")

})

Try the MazamaWebUtils package in your browser

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

MazamaWebUtils documentation built on May 2, 2019, 2:41 a.m.