Learn R Programming

precommithooks (version 0.0.0.9007)

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 fuffix 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.

comparator

A function thtat takes two paths as arguments: One to a file after the hooks has been applied and one to a reference file. Only used if error_msg is not NULL.

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.