ut_cmp_error: Test for and compare errors generated by code

View source: R/ut_cmp_error.R

ut_cmp_errorR Documentation

Test for and compare errors generated by code

Description

A helper to catch expected errors and ensure they match what is expected

Usage

  ut_cmp_error(code, expected_regexp, ignore.case = FALSE, perl = FALSE, fixed = FALSE)

Arguments

code

Code expression to test, should generate an error

expected_regexp

Regular expression the error should match

ignore.case

Passed to grepl

perl

Passed to grepl

fixed

Passed to grepl

Value

Returns TRUE if exp generates an error and matches expected_regexp. Returns a string with expected and actual error if exp generates an error but does not match. Returns "No error returned" if exp does not generate an error.

Examples

ok(ut_cmp_error({
  stop("Hammer time")
}, "hammer", ignore.case = TRUE), "Returned a hammer-based error")



unittest documentation built on May 4, 2023, 5:12 p.m.