run_test | R Documentation |
Tests for the executables used as pre-commit hooks via entrypoint
in
.pre-commit-config.yaml
. Set's the env variable R_PRECOMMIT_HOOK_ENV
to
when running.
run_test(
hook_name,
file_name = hook_name,
suffix = ".R",
std_err = NULL,
std_out = NULL,
cmd_args = NULL,
artifacts = NULL,
file_transformer = function(files) files,
env = character(),
expect_success = is.null(std_err),
read_only = FALSE
)
hook_name |
The name of the hook in |
file_name |
The file to test in |
suffix |
The suffix of |
std_err |
An expected error message. If no error is expected, this
can be |
std_out |
The expected stdout message. If |
cmd_args |
More arguments passed to the file. Pre-commit handles it as described here. |
artifacts |
Path with artifact files to copy to the temp directory root where the test is run. If you don't target the root, this can be a named vector of length one where the name is the target location relative to the temporary location and the value is the source of the file. |
file_transformer |
A function that takes the file names as input and is
ran right before the hook script is invoked, returning the path to the
files, potentially modified (if renamed). This can be useful if you need to
make in-place modifications to the file, e.g. to test hooks that operate on
|
env |
The environment variables to set with |
expect_success |
Whether or not an exit code 0 is expected. This can
be derived from |
read_only |
If |
Two potential outcomes of a hooks are pass or fail. This is reflected on the level of the executable: Fail means the executable fails or the file is changed. Pass means the executable succeeds and the file is unchanged. We check if the executable passes as follows:
If we expect success (by setting std_err
to NULL
), we make sure
nothing was written to sterr and the file content does not change.
If we expect failure, it can be due to changed file or due to failed
executable. To check for failed executable, we set std_err
to
the message we expect. To check changed file content, we set std_err
to
NA
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.