R/ut_cmp_error.R

Defines functions ut_cmp_error

Documented in ut_cmp_error

# Code block (exp) is assumed to throw an error, to be compared against (expected_regexp)
# All other options are handed to grepl()
ut_cmp_error <- function(code, expected_regexp, ignore.case = FALSE, perl = FALSE, fixed = FALSE) {
    tryCatch({
        code
        return("No error returned")
    }, error = function(e) {
        if (grepl(expected_regexp, e$message, ignore.case = ignore.case, perl = perl, fixed = fixed)) {
            return(TRUE)
        }
        return(c(e$message, "Did not match:-", expected_regexp))
    })
}

Try the unittest package in your browser

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

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