Learn R Programming

precommit (version 0.1.3)

run_test: Run a test

Description

Tests for the executables used as pre-commit hooks via entrypoint in .pre-commit-config.yaml.

Usage

run_test(
  hook_name,
  file_name = hook_name,
  suffix = ".R",
  error_msg = NULL,
  cmd_args = NULL,
  copy = NULL
)

Arguments

hook_name

The name of the hook in bin/.

file_name

The file to test in tests/in (without extension).

suffix

The suffix of file_name.

error_msg

An expected error message. If no error is expected, this can be NULL. In that case, the comparator is applied.

cmd_args

More arguments passed to the file. Pre-commit handles it as described here.

copy

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.

Details

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.