ok: The unittest package's workhorse function

View source: R/ok.R

okR Documentation

The unittest package's workhorse function

Description

Report the test of an expression in TAP format.

Usage

  ok(test, description)

Arguments

test

Expression to be tested. Evaluating to TRUE is treated as success, anything else as failure.

description

Character string describing the test. If a description is not given a character representation of the test expression will be used.

Details

See unittest package documentation.

The unittest.output option tells unittest where output should be sent. This is most useful for vignettes, where sending output to stderr separates the unittest output from the vignette itself.

Value

ok() returns whatever was returned when test is evaluated. More importantly it has the side effect of printing the result of the test in TAP format.

Examples

ok(1==1, "1 equals 1")

ok(1==1)

ok(1==2, "1 equals 2")

ok(all.equal(c(1,2),c(1,2)), "compare vectors")

fn <- function () stop("oops")
ok(fn(), "something with a coding error")

ok(c("Some diagnostic", "messages"), "A failure with diagnostic messages")

## Send unittest output to stderr()
options(unittest.output = stderr())
ok(ut_cmp_equal(4, 5), "4 == 5? Probably not")

## Reset unittest output to default (stdout())
options(unittest.output = NULL)
ok(ut_cmp_equal(4, 5), "4 == 5? Probably not")



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