makeTest: Turn a Check into a Test

Description Usage Arguments Value See Also Examples

Description

makeTest is the internal function used to evaluate the result of a check and throw an exception if necessary. This function is currently only a stub and just calls isTRUE. makeTestFunction can be used to automatically create an assertion function based on a check function (see example).

Usage

1
2
3
makeTest(res)

makeTestFunction(check.fun, c.fun = NULL, env = parent.frame())

Arguments

res

[TRUE | character(1)]
The result of a check function: TRUE for successful checks, and an error message as string otherwise.

check.fun

[function]
Function which checks the input. Must return TRUE on success and a string with the error message otherwise.

c.fun

[character(1)]
If not NULL, instead of calling the function check.fun, use .Call to call a C function “c.fun” with the identical set of parameters. The C function must be registered as a native symbol, see .Call. Useful if check.fun is just a simple wrapper.

env

[environment]
The environment of the created function. Default is the parent.frame.

Value

makeTest returns TRUE if the check is successful and FALSE otherwise. makeTestFunction returns a function.

See Also

Other CustomConstructors: makeAssertion, makeExpectation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Simple custom check function
checkFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE

# Create the respective test function
testFalse = function(x) {
  res = checkFalse(x)
  makeTest(res)
}

# Alternative: Automatically create such a function
testFalse = makeTestFunction(checkFalse)
print(testFalse)

checkmate documentation built on July 4, 2019, 5:12 p.m.