Learn R Programming

runittotestthat (version 0.0-2)

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

Description

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

Usage

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").

See Also

convert_package_tests, convert_test

Examples

Run this code
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)

Run the code above in your browser using DataLab