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
31
  ## 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

  ok(stop("oops"), "something with a coding error")
  # not ok - something with a coding error
  # # Test resulted in error: oops
  # #  -> doTryCatch
  # #  -> return(expr)
  # #  -> name
  # #  -> parentenv
  # #  -> handler

  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 May 29, 2017, 3:35 p.m.

Search within the unittest package
Search all R packages, documentation and source code