generateUnitTestFile: Generate Testthat Unit Test File

Description Usage Arguments Value Note Author(s) References Examples

View source: R/generateUnitTestFile.R

Description

Generate one testthat unit test file from an instrumented offensive programming object. One test file per function is created. It holds all the related tests, organized by evaluation mode. See EvaluationMode for more information.

Usage

1
2
3
generateUnitTestFile(filename_s_1, content_s,
                     overwrite_b_1 = FALSE,
                     verbose_b_1 = TRUE)

Arguments

filename_s_1

the name of the unit test file to generate

content_s

the content of the unit test file to generate

overwrite_b_1

A boolean value, either TRUE or FALSE to switch on or off the overwritting of the output file.

verbose_b_1

A boolean value, either TRUE or FALSE to switch on or off the output message from this function.

Value

Returns the file name.

It might be different from the one provided, as testthat requires to follow some file naming conventions that are enforced by this function.

Note

This function is provided for convenience. It may ease your own way to generate testthat code.

To put this package in action, simply use gautfo that offers a much more straightforward way to get results.

Author(s)

Fabien Gelineau <neonira@gmail.com>

Maintainer: Fabien Gelineau <neonira@gmail.com>

References

Refer to test_file from package testthat.

Refer to runTestCase from package wyz.code.offensiveProgramming.

Examples

1
2
3
4
5
6
##---- typical example ----
fn <- file.path(tempdir(), 'myFile')
fr <- generateUnitTestFile(fn, c("# a comment", "x <- 2"))
cat(paste(readLines(fr$filename), collapse  = '\n'))
# a comment
# x <- 2

wyz.code.testthat documentation built on Oct. 6, 2021, 9:07 a.m.