ok: The unittest package's workhorse function

Description Usage Arguments Details Value Examples

View source: R/ok.R

Description

Report the test of an expression in TAP format.

Usage

1
  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.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  ## Not run: 
  ok(1==1, "1 equals 1")
  # ok - 1 equals 1

  ok(1==1)
  # ok - 1 == 1

  ok(1==2, "1 equals 2")
  # not ok - 1 equals 2
  # # Test returned non-TRUE value:
  # # [1] FALSE

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

  fn <- function () stop("oops")
  ok(fn(), "something with a coding error")
  # not ok - something with a coding error
  # # Test resulted in error:
  # #  oops
  # # Whilst evaluating:
  # #  fn()

  ok(c("Some diagnostic", "messages"), "A failure with diagnostic messages")
  # not ok - A failure with diagnostic messages
  # # Test returned non-TRUE value:
  # # Some diagnostic
  # # messages
  
## End(Not run)

unittest documentation built on Nov. 17, 2017, 4:30 a.m.