Title: | Document Unit Tests Roxygen-Style |
---|---|
Description: | Much as 'roxygen2' allows one to document functions in the same file as the function itself, 'roxut' allows one to write the unit tests in the same file as the function. Once processed, the unit tests are moved to the appropriate directory. Currently supports 'testthat' and 'tinytest' frameworks. The 'roxygen2' package provides much of the infrastructure. |
Authors: | Bryan A. Hanson [aut, cre] |
Maintainer: | Bryan A. Hanson <[email protected]> |
License: | GPL-3 |
Version: | 0.4.3 |
Built: | 2025-02-05 05:11:30 UTC |
Source: | https://github.com/bryanhanson/roxut |
Much as roxygen2
allows one to document functions in the same file
as the function itself, roxut
allows one to write the unit tests
in the same file as the function. Once processed, the unit tests are
moved to the appropriate directory. Currently supports testthat
and
tinytest
frameworks. The roxygen2
package provides much of the infrastructure.
Bryan A. Hanson.
Maintainer: Bryan A. Hanson [email protected]
Delete unit test files generated by @tests tags. Activated when
calling roxygenize
with clean = TRUE
.
## S3 method for class 'roclet_tests' roclet_clean(x, base_path)
## S3 method for class 'roclet_tests' roclet_clean(x, base_path)
x |
A |
base_path |
Path to root of source package. |
NULL If found, files created by roxut
will be deleted.
Bryan A. Hanson
The contents of the unit tests (lines following the @tests
tags)
are written verbatim to the appropriate directories (directory depends
on whether tinytest
or testthat
is in use). If there is more
than one function and corresponding unit tests in a file, the first unit tests
will be in filename.R
, the second in filename-1.R
etc.
## S3 method for class 'roclet_tests' roclet_output(x, results, base_path, ...)
## S3 method for class 'roclet_tests' roclet_output(x, results, base_path, ...)
x |
A |
results |
Value returned from the |
base_path |
Path to root of source package. |
... |
Other arguments passed downstream. Needed for compatibility, does not appear to be used. |
Invisibly, a list with the text of the tests. Writes files!
Bryan A. Hanson
Processes the blocks containing the @tests
tags.
## S3 method for class 'roclet_tests' roclet_process(x, blocks, env, base_path)
## S3 method for class 'roclet_tests' roclet_process(x, blocks, env, base_path)
x |
A |
blocks |
A list of |
env |
Package environment. |
base_path |
Path to root of source package. |
A list.
Bryan A. Hanson
This function is called once for each @tests
tag in a
function definition file.
## S3 method for class 'roxy_tag_tests' roxy_tag_parse(x)
## S3 method for class 'roxy_tag_tests' roxy_tag_parse(x)
x |
A |
The x
object is returned, appended with a list val
containing two elements:
framework
containing the name of the unit test framework in use.
tests
containing the content of the unit tests.
Bryan A. Hanson
This roclet automates the creation of unit tests, using @tests
tags
written in the function definition files, and processed using roxygen2
.
The unit tests are written verbatim to the appropriate destination file.
tests_roclet()
tests_roclet()
A complete roclet.
Bryan A. Hanson
# In actual use, the test lines would be in your function definition file. # The results (cat'd here) would be written to the unit test file. # If the function definition file is myFunc.R then the results # are written to test-myFunc.R in the appropriate directory # (the directory depends on whether your are using tinytest or testthat). tinytest_in <- "#' @tests tinytest\n#' # Are these equal?\n#' expect_equal(5.0, 5.0)\nNULL\n" tinytest_out <- roxygen2::roc_proc_text(tests_roclet(), tinytest_in) cat(tinytest_out$tinytest, "\n") testthat_in <- "#' @tests testthat\n#' # Are these equal?\n#' expect_equal(5.0, 5.0)\nNULL\n" testthat_out <- roxygen2::roc_proc_text(tests_roclet(), testthat_in) cat(testthat_out$testthat, "\n")
# In actual use, the test lines would be in your function definition file. # The results (cat'd here) would be written to the unit test file. # If the function definition file is myFunc.R then the results # are written to test-myFunc.R in the appropriate directory # (the directory depends on whether your are using tinytest or testthat). tinytest_in <- "#' @tests tinytest\n#' # Are these equal?\n#' expect_equal(5.0, 5.0)\nNULL\n" tinytest_out <- roxygen2::roc_proc_text(tests_roclet(), tinytest_in) cat(tinytest_out$tinytest, "\n") testthat_in <- "#' @tests testthat\n#' # Are these equal?\n#' expect_equal(5.0, 5.0)\nNULL\n" testthat_out <- roxygen2::roc_proc_text(tests_roclet(), testthat_in) cat(testthat_out$testthat, "\n")