# NOT RUN {
assertError(sqrt("abc"))
assertWarning(matrix(1:8, 4,3))
assertCondition( ""-1 ) # ok, any condition would satisfy this
try( assertCondition(sqrt(2), "warning") )
## .. Failed to get warning in evaluating sqrt(2)
assertCondition(sqrt("abc"), "error") # ok
try( assertCondition(sqrt("abc"), "warning") )# -> error: had no warning
assertCondition(sqrt("abc"), "error")
## identical to assertError() call above
assertCondition(matrix(1:5, 2,3), "warning")
try( assertCondition(matrix(1:8, 4,3), "error") )
## .. Failed to get expected error ....
## either warning or worse:
assertCondition(matrix(1:8, 4,3), "error","warning") # OK
assertCondition(matrix(1:8, 4, 3), "warning") # OK
## when both are signalled:
ff <- function() { warning("my warning"); stop("my error") }
assertCondition(ff(), "warning")
## but assertWarning does not allow an error to follow
try(assertWarning(ff()))
assertCondition(ff(), "error") # ok
assertCondition(ff(), "error", "warning") # ok (quietly, catching warning)
## assert that assertC..() does not assert [and use *one* argument only]
assertCondition( assertCondition(sqrt( 2 ), "warning") )
assertCondition( assertCondition(sqrt("abc"), "warning"), "error")
assertCondition( assertCondition(matrix(1:8, 4,3), "error"),
"error")
# }
Run the code above in your browser using DataLab