Tests for the executables used as pre-commit hooks via entrypoint
in
.pre-commit-config.yaml
.
run_test(
hook_name,
file_name = hook_name,
suffix = ".R",
error_msg = NULL,
cmd_args = NULL,
copy = NULL
)
The name of the hook in bin/
.
The file to test in tests/in
(without extension).
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.
More arguments passed to the file. Pre-commit handles it as described here.
Path with files to copy to the temp directory where the test is run. If the target destination relative to the temp dir where the hook is tested is not identical to the path from where a file should be copied, you can pass a named vector. The name is the target directory relative to the temp directory where the hook is executed (the temp directory will be the working directory at that time) and the value is the path that points to the place where the artifact is currently stored.
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 error_msg
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 executalble, we set error_msg
to
the message we expect. To check changed file content, we set error_msg
to
NA
.