convert_test_file: Convert a file worth of RUnit tests to testthat tests

Description Usage Arguments Value Note See Also Examples

View source: R/convert.R

Description

Converts all RUnit tests in a file to testthat tests, and writes them out to another file.

Usage

1
2
convert_test_file(runit_file, test_func_regexp = "^test.+",
  testthat_file = stdout())

Arguments

runit_file

A path to an file containing RUnit tests.

test_func_regexp

Regular expression determining which functions in the tests files are considered to be tests.

testthat_file

String of path for the output file. Defaults to stdout() to prevent you overwriting your existing test files. See note.

Value

A list of calls to test_that is invisibly returned. This list is also written to an output connection (defaulting to stdout). An environment containing the original RUnit is stored in attr(, "runit_tests").

Note

RUnit tests will be evaluated when they are read in, so make sure that all your tests pass before you convert them.

The testthat_file argument can be based upon the runit_file argument. For example, if you use the traditional RUnit test file naming strategy, something like sub("^runit", "testthat", runit_file) may be appropriate.

See Also

convert_package_tests, convert_test

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
tmp <- tempfile("test-convert_test_file")
writeLines(
  "test_truth <- function()
{
  x <- all(runif(10) > 0)
  checkTrue(x)
}
test_equality <- function()
{
  x <- sqrt(1:5)
  expected <- c(1, 4, 9, 16, 25)
  checkEquals(expected, x ^ 4)
}
test_error <- function()
{
  checkException('1' + '2')
}",
  tmp
)
convert_test_file(tmp)
unlink(tmp)

runittotestthat documentation built on May 2, 2019, 9:36 a.m.