convert_test_file

0th

Percentile

Convert a file worth of RUnit tests to testthat tests

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

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

Aliases
  • convert_test_file
Examples
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)
Documentation reproduced from package runittotestthat, version 0.0-2, License: Unlimited

Community examples

Looks like there are no examples yet.