tests/testthat/test_tryCatchAll.R

context("tryCatchAll")
NMdataConf(reset=TRUE)


test_that("Basic",{
    fileRef <- "testReference/tryCatchAll_01.rds"


    testfun <- function(x) {
        message("Starting function")
        if (x == 0) warning("x is zero")
        if (x < 0) stop("x is negative")
        message("Ending function")
        x
    }

    res1 <- tryCatchAll(testfun(1))  
    res1
    res1b <- tryCatchAll(testfun(1),message=FALSE)  
    res1b

    res2 <- tryCatchAll(testfun(0))  
    res2

    res3 <- tryCatchAll(testfun(-1)) 
    res3

    res.all <- list(res1,res1b,res2,res3)
    expect_equal_to_reference(res.all,fileRef)

})

Try the NMdata package in your browser

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

NMdata documentation built on Aug. 8, 2025, 7:40 p.m.