register_tinytest_extension: Register or unregister extension functions

View source: R/tinytest.R

register_tinytest_extensionR Documentation

Register or unregister extension functions

Description

Functions to use in .onLoad and .onUnload by packages that extend tinytest.

Usage

register_tinytest_extension(pkg, functions)

Arguments

pkg

[character] scalar. Name of the package providing extensions.

functions

[character] vector. Name of the functions in the package that must be added.

The tinytest API

Packages can extend tinytest with expectation functions if and only if the following requirements are satisfied.

  1. The extending functions return a tinytest object. This can be created by calling tinytest() with the arguments (defaults, if any, are in brackets):

    • result: A logical scalar: TRUE or FALSE (not NA)

    • call: The call to the expectation function. Usually the result of sys.call(sys.parent(1))

    • diff (NA_character_): A character scalar, with a long description of the difference. Sentences may be separated by "\n".

    • short (NA_character_): Either "data", if the difference is in the data. "attr" when attributes differ or "xcpt" when an expectation about an exception is not met. If there are differences in data and in attributes, the attributes take precedence.

    • info (NA_character_): A user-defined message.

    Observe that this requires the extending package to add tinytest to the Imports field in the package's DESCRIPTION file (this also holds for the following requirement).

  2. Functions are registered in .onLoad() using register_tinytest_extension(). Functions that are already registered, including tinytest functions will be overwritten.

It is recommended to:

  1. Follow the syntax conventions of tinytest so expectation functions start with expect_.

  2. Explain to users of the extension package how to use the extension (see using).

  3. include an info argument to expect_ functions that is passed to tinytest().

Minimal example packages

See Also

Other extensions: tinytest(), using()


tinytest documentation built on March 7, 2023, 7:43 p.m.