Title: | Handle Long Tests in Bioconductor Packages |
---|---|
Description: | This package provides a roclet for roxygen2 that identifies and processes code blocks in your documentation marked with `@longtests`. These blocks should contain tests that take a long time to run and thus cannot be included in the regular test suite of the package. When you run `roxygen2::roxygenise` with the `longtests_roclet`, it will extract these long tests from your documentation and save them in a separate directory. This allows you to run these long tests separately from the rest of your tests, for example, on a continuous integration server that is set up to run long tests. |
Authors: | Francesc Catala-Moll [aut, cre] |
Maintainer: | Francesc Catala-Moll <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.3.0 |
Built: | 2024-10-30 04:21:21 UTC |
Source: | https://github.com/bioc/biocroxytest |
This roclet is used to identify and process code blocks in your documentation
that are marked with @longtests
. The longtests_roclet
function creates a
new roclet, which is a plugin to the roxygen2
package. Roclets are
responsible for parsing the R scripts of a package and producing the relevant
documentation files.
longtests_roclet()
longtests_roclet()
The longtests_roclet
specifically looks for code blocks in your
documentation that are annotated with the @longtests
tag. These code blocks
should contain tests that take a long time to run, and thus cannot be
included in the regular test suite of the package.
When you run roxygen2::roxygenise
with the longtests_roclet
, it will
extract these long tests from your documentation and save them in a separate
directory. This allows you to run these long tests separately from the rest
of your tests, for example, on a continuous integration server that is set up
to run long tests.
A roclet that can be used with roxygen2
to process code blocks
marked with @longtests
. This roclet will produce a set of test files in a
separate directory, which can be run independently of the rest of your test
suite.
# Create a new roclet longtests_roclet()
# Create a new roclet longtests_roclet()
This function cleans up test files in the 'longtests' directory of a given
base path. It first verifies if 'longtests' is used in the package by calling
verify_longtests_used()
. Then, it finds all test files in the 'longtests'
directory that match the pattern "test-biocroxytest-.*\.R$". Finally, it
calls internal_longtests_roclet_clean(testfiles)
to remove the test files
generated by biocroxytest.
## S3 method for class 'roclet_longtests' roclet_clean(x, base_path)
## S3 method for class 'roclet_longtests' roclet_clean(x, base_path)
x |
An object of class 'roclet_longtests'. |
base_path |
A character string representing the base path of the package. |
Invisible NULL.
# Set up a temporary directory base_path <- tempdir() longtests_path <- file.path(base_path, "longtests") unlink(longtests_path, recursive = TRUE, force = TRUE) dir.create(longtests_path, recursive = TRUE, showWarnings = FALSE) # Create dummy inputs obj <- longtests_roclet() # Run the roclet_output function result <- roxygen2::roclet_clean(obj, base_path)
# Set up a temporary directory base_path <- tempdir() longtests_path <- file.path(base_path, "longtests") unlink(longtests_path, recursive = TRUE, force = TRUE) dir.create(longtests_path, recursive = TRUE, showWarnings = FALSE) # Create dummy inputs obj <- longtests_roclet() # Run the roclet_output function result <- roxygen2::roclet_clean(obj, base_path)
This function processes a list of blocks for the 'longtests' roclet. It calls the 'internal_longtests_roclet_process' function with the specified blocks and additional arguments. The code in the tests is indented, a 'test_that' boilerplate is added to the tests, and a 'context' line is not added to the header.
## S3 method for class 'roclet_longtests' roclet_output(x, results, base_path, ...)
## S3 method for class 'roclet_longtests' roclet_output(x, results, base_path, ...)
x |
An object of class 'roclet_longtests'. package. |
results |
A list with a single element 'longtests', which contains the |
base_path |
A character string representing the base path of the |
... |
Additional arguments passed to the function. |
A list with a single element 'longtests', which contains the processed test files.
# Set up a temporary directory base_path <- tempdir() longtests_path <- file.path(base_path, "longtests", "testthat") unlink(longtests_path, recursive = TRUE, force = TRUE) dir.create(longtests_path, recursive = TRUE, showWarnings = FALSE) # Create dummy inputs obj <- longtests_roclet() results <- list(longtests = list()) # Run the roclet_output function result <- roxygen2::roclet_output(obj, results, base_path)
# Set up a temporary directory base_path <- tempdir() longtests_path <- file.path(base_path, "longtests", "testthat") unlink(longtests_path, recursive = TRUE, force = TRUE) dir.create(longtests_path, recursive = TRUE, showWarnings = FALSE) # Create dummy inputs obj <- longtests_roclet() results <- list(longtests = list()) # Run the roclet_output function result <- roxygen2::roclet_output(obj, results, base_path)
This function processes a list of blocks for the 'longtests' roclet. It calls the 'internal_longtests_roclet_process' function with the specified blocks and additional arguments. The code in the tests is indented, a 'test_that' boilerplate is added to the tests, and a 'context' line is not added to the header.
## S3 method for class 'roclet_longtests' roclet_process(x, blocks, env, base_path)
## S3 method for class 'roclet_longtests' roclet_process(x, blocks, env, base_path)
x |
An object of class 'roclet_longtests'. |
blocks |
A list of roxygen2 blocks. |
env |
The environment in which the roxygen2 blocks were parsed. |
base_path |
A character string representing the base path of the package. |
A list with a single element 'longtests', which contains the processed test files.
# Create a dummy block function block <- function(roclet, value) { list(roclet = roclet, value = value) } # Create a new roclet_longtests object x <- longtests_roclet() # Define some roxygen2 blocks blocks <- list( block( roclet = "longtests", value = list( raw = "test_that('this is a test', { expect_equal(1, 1) })" ) ) ) blocks <- structure(blocks, class = "roclet_longtests") # Define the environment and base path env <- globalenv() base_path <- tempdir() # Process the blocks roxygen2::roclet_process(x, blocks, env, base_path)
# Create a dummy block function block <- function(roclet, value) { list(roclet = roclet, value = value) } # Create a new roclet_longtests object x <- longtests_roclet() # Define some roxygen2 blocks blocks <- list( block( roclet = "longtests", value = list( raw = "test_that('this is a test', { expect_equal(1, 1) })" ) ) ) blocks <- structure(blocks, class = "roclet_longtests") # Define the environment and base path env <- globalenv() base_path <- tempdir() # Process the blocks roxygen2::roclet_process(x, blocks, env, base_path)
This function is used to set up the environment for running long tests. It
calls two helper functions: setup_bboptions()
and setup_longtetsts()
.
use_longtests()
use_longtests()
The use_longtests()
function is a wrapper function that calls
setup_bboptions()
and setup_longtetsts()
. The setup_bboptions()
function checks if the .BBSoptions file exists and creates it if it doesn't.
It then checks the contents of the .BBSoptions file and adds or modifies the
'RunLongTests: TRUE' line as needed. The setup_longtetsts()
function
creates a 'longtests/testthat' directory if it doesn't exist and copies the
'tests/testthat.R' file into it. If the 'tests/testthat.R' file doesn't
exist, it creates a new one with default content.
This function does not return a value. It is used for its side effects of setting up the environment for running long tests.
# Create the longtests directory and .BBSoptions file use_longtests() # Remove the longtests directory and .BBSoptions file unlink(file.path(".BBSoptions"), recursive = TRUE, force = TRUE) unlink(file.path("longtests"), recursive = TRUE, force = TRUE)
# Create the longtests directory and .BBSoptions file use_longtests() # Remove the longtests directory and .BBSoptions file unlink(file.path(".BBSoptions"), recursive = TRUE, force = TRUE) unlink(file.path("longtests"), recursive = TRUE, force = TRUE)