An object of class tinytests (note: plural) results
from running multiple tests from script. E.g. by running
run_test_file.
Usage
# S3 method for class 'tinytests'
summary(object, ...)
all_pass(x)
any_pass(x)
all_fail(x)
any_fail(x)
# S3 method for class 'tinytests'
x[i]
# S3 method for class 'tinytests'
print(
x,
passes = getOption("tt.pr.passes", FALSE),
sidefx = getOption("tt.pr.sidefx", TRUE),
limit = getOption("tt.pr.limit", 7),
nlong = getOption("tt.pr.nlong", 3),
...
)
# S3 method for class 'tinytests'
as.data.frame(x, ...)Arguments
- object
a
tinytestsobject- ...
passed to
format.tinytest- x
a
tinytestsobject- i
an index
- passes
[logical]Toggle: print passing tests?- sidefx
[logical]Toggle: print side effects?- limit
[numeric]Max number of results to print- nlong
[numeric]Firstnlongresults are printed in long format.
Value
For summary a table object
For all_pass, any_pass, all_fail, any_fail:
a single logical
For `[.tinytests` a tinytests object.
For as.data.frame. a data frame.
Details
By default, the first 3 failing test results are printed in long form,
the next 7 failing test results are printed in short form and all other
failing tests are not printed. These defaults can be changed by passing options
to print.tinytest, or by setting one or more of the following global
options:
tt.pr.passesSet toTRUEto print output of non-failing tests.tt.pr.limitMax number of results to print (e.g.Inf)tt.pr.nlongThe number of results to print in long format (e.g.Inf).
For example, set options(tt.pr.limit=Inf) to print all test results.
Furthermore, there is the option
tt.pr.color,
which determines whether colored output is printed.
If R is running in a dumb terminal (detected by comparing
environment variable "TERM" to "dumb"), then
this option is set to FALSE when the package is loaded.
See also
Other test-files:
build_install_test(),
exit_file(),
run_test_dir(),
run_test_file(),
test_package()
Examples
# create a test file in tempdir
tests <- "
addOne <- function(x) x + 2
expect_true(addOne(0) > 0)
expect_equal(2, addOne(1))
"
testfile <- tempfile(pattern="test_", fileext=".R")
write(tests, testfile)
# extract testdir
testdir <- dirname(testfile)
# run all files starting with 'test' in testdir
out <- run_test_dir(testdir)
#>
test_35396019b4776d.R......... 0 tests
test_35396019b4776d.R......... 0 tests
test_35396019b4776d.R......... 1 tests OK
test_35396019b4776d.R......... 2 tests 1 fails
test_35396019b4776d.R......... 2 tests 1 fails 5ms
#>
test_35396055711e62.R......... 0 tests
test_35396055711e62.R......... 1 tests OK
test_35396055711e62.R......... 2 tests 1 fails 1ms
#>
test_353960cc12900.R.......... 0 tests
test_353960cc12900.R.......... 1 tests OK
test_353960cc12900.R.......... 2 tests 1 fails 1ms
#
# print results
print(out)
#> ----- FAILED[data]: test_35396019b4776d.R<7--7>
#> call| expect_equal(2, addOne(1))
#> diff| Expected '3', got '2'
#> ----- FAILED[data]: test_35396055711e62.R<5--5>
#> call| expect_equal(2, addOne(1))
#> diff| Expected '3', got '2'
#> ----- FAILED[data]: test_353960cc12900.R<5--5>
#> call| expect_equal(2, addOne(1))
#> diff| Expected '3', got '2'
#>
#> Showing 3 out of 6 results: 3 fails, 3 passes (8ms)
summary(out)
#>
#> File Results fails passes
#> test_35396019b4776d.R 2 1 1
#> test_35396055711e62.R 2 1 1
#> test_353960cc12900.R 2 1 1
#> Total 6 3 3
dat <- as.data.frame(out)
out[1]
#> All ok, 1 results fubar!