Learn R Programming

RTest (version 1.2.6)

test_execution: Tests Silent Execution of an Function

Description

Tests Silent Execution of an Function

Usage

test_execution(what, args, xmlTestSpec = NULL, ...)

Arguments

what, args

Parameters for execution of the test function (see do.call).

xmlTestSpec

(XMLNode) The XML definition of type 'RTestTest_variable'.

...

Additional parameters passed to do.call.

Value

ANY result of test functin

See Also

do.call

Examples

Run this code
# NOT RUN {
value <- test_execution(
      "sum",
      list(x=2,y=3),
      xmlTestSpec=XML::xmlNode(
          name="execution",
          attrs=list('execution-type'="silent"))
)
stopifnot(value==5)

# Create a function that always produces warnings

sum_test <- function(...){
  warning("test")
  sum(...)
}

# Let this function run and crash, if it crashes check if the error contains "produced warnings"

tryCatch(
test_execution(
   "sum_test",
    list(x=2,y=3),
   xmlTestSpec=XML::xmlNode(name="execution",attrs=list("execution-type"="silent"))
 ),error=function(e){
    stopifnot(grepl("produced warnings",e))
 })
# }

Run the code above in your browser using DataLab