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.
The name of the hook in inst/hooks/exported/
, without
file extension.
The file to test in tests/in
(without extension). 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.
The suffix of file_name
.
An expected error message. If no error is expected, this
can be NULL
. In that case, the comparator
is applied.
The expected stdout message. If NULL
, this check is omitted.
More arguments passed to the file. Pre-commit handles it as described here.
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.
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
.Rprofile
. You can't have different names for different tests on that
file because it must be called .Rprofile
all the time. And R CMD check
seems to remove hidden files, so we must also rename it. The transformation
is also applied to a temp copy of the reference file before a comparison is
made.
The environment variables to set with base::system2()
.
Whether or not an exit code 0 is expected. This can
be derived from std_err
, but sometimes, non-empty stderr does not mean
error, but just a message.
If TRUE
, then assert that no new files were created.
Additionally, if artifacts
are not NULL
, then assert that hook did not
modify the artifacts.
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
.