Learn R Programming

exampletestr (version 1.3.1)

make_test_shell: Make the shell of a test_that test.

Description

Given a character vector of the examples from a function, create the shell of a testthat::test_that() code block (to be filled in by the user) based upon those examples.

Usage

make_test_shell(example_block, desc = "", e_e = TRUE)

Arguments

example_block

A character vector of the lines in the examples of a function's documentation.

desc

To be the desc argument of the testthat::test_that() call.

e_e

Set this to FALSE to prevent anything from being put in the shell of an expect_equal() statement.

Value

A character vector giving the shell of a test_that function call testing all of the calls in the example block.

Details

Assignment lines (lines with <-, or even an = assignment (naughty, I know)) and lines starting with print(, stop(, warning(, setwd(, plot(, ggplot(, set.seed or library( are left alone, others are put in the shell of an expect_equal() statement. To prevent anything from being put in the shell of an expect_equal() statement, set e_e = FALSE. Anything found within a \dontrun{...} block is ignored.

Examples

Run this code
# NOT RUN {
devtools::create("tempkg")
setwd("tempkg")
file.copy(system.file("extdata", "detect.R", package = "exampletestr"), "R")
devtools::document()
make_test_shell(extract_examples("detect")[[1]])
make_test_shell(extract_examples("detect")[[1]],
                desc = "xyz", e_e = FALSE)
setwd("..")
filesstrings::dir.remove("tempkg")

# }

Run the code above in your browser using DataLab