| Title: | Additional Expecation Predicates for the 'tinytest' Testing Framework |
|---|---|
| Description: | Ports of 'testthat' expectation predicates to the 'tinytest' testing framework. These ports allow easier transitioning from 'testthat' to 'tinytest' as well as provide more explicit expectation predicates for 'tinytest' users. |
| Authors: | Paul Hoffman [aut, cre] (ORCID: <https://orcid.org/0000-0002-7693-8957>) |
| Maintainer: | Paul Hoffman <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.0.9010 |
| Built: | 2026-05-21 07:18:39 UTC |
| Source: | https://github.com/mojaveazure/tinyexpect |
Expectation predicate for testing based on comparisons
expect_lt(current, target, ..., info = NA_character_) expect_lte(current, target, ..., info = NA_character_) expect_gt(current, target, ..., info = NA_character_) expect_gte(current, target, ..., info = NA_character_)expect_lt(current, target, ..., info = NA_character_) expect_lte(current, target, ..., info = NA_character_) expect_gt(current, target, ..., info = NA_character_) expect_gte(current, target, ..., info = NA_character_)
current |
|
target |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalents:
expect_lt(),
expect_lte(),
expect_gt(), and
expect_gte()
# Expect strictly less than expect_lt(1L, 3L) # Pass expect_lt(3L, 1L) # Fail expect_lt(1L, 1L) # Fail # Expect less than or equal to expect_lte(1L, 3L) # Pass expect_lte(3L, 1L) # Fail expect_lte(1L, 1L) # Pass # Expect strictly greater than expect_gt(1L, 3L) # Fail expect_gt(3L, 1L) # Pass expect_gt(1L, 1L) # Fail # Expect greater than or equal to expect_gte(1L, 3L) # Fail expect_gte(3L, 1L) # Pass expect_gte(1L, 1L) # Pass# Expect strictly less than expect_lt(1L, 3L) # Pass expect_lt(3L, 1L) # Fail expect_lt(1L, 1L) # Fail # Expect less than or equal to expect_lte(1L, 3L) # Pass expect_lte(3L, 1L) # Fail expect_lte(1L, 1L) # Pass # Expect strictly greater than expect_gt(1L, 3L) # Fail expect_gt(3L, 1L) # Pass expect_gt(1L, 1L) # Fail # Expect greater than or equal to expect_gte(1L, 3L) # Fail expect_gte(3L, 1L) # Pass expect_gte(1L, 1L) # Pass
Expectation predicate for testing that a given function call throws a condition
expect_condition( current, pattern = NULL, class = NULL, ..., info = NA_character_ )expect_condition( current, pattern = NULL, class = NULL, ..., info = NA_character_ )
current |
|
pattern |
|
class |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_condition()
Other condition expectation predicates:
expect_no_condition()
expect_condition(message("test message")) # Pass expect_condition(warning("test warning")) # Pass expect_condition(stop("test error")) # Pass expect_condition("tomato") # Fail expect_condition(message("test message"), class = "specialMessage") # Fail expect_condition(message("test message"), pattern = "tomato") # Failexpect_condition(message("test message")) # Pass expect_condition(warning("test warning")) # Pass expect_condition(stop("test error")) # Pass expect_condition("tomato") # Fail expect_condition(message("test message"), class = "specialMessage") # Fail expect_condition(message("test message"), pattern = "tomato") # Fail
Expectation predicate for testing that a given vector contains all values present in another vector
expect_contains(current, target, ..., info = NA_character_)expect_contains(current, target, ..., info = NA_character_)
current |
|
target |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_contains()
Other in-condition expectation predicates:
expect_in(),
expect_mapequal(),
expect_setequal()
expect_contains(letters, target = rev(letters)) # Pass expect_contains(letters, target = "b") # Pass expect_contains("b", target = letters) # Failexpect_contains(letters, target = rev(letters)) # Pass expect_contains(letters, target = "b") # Pass expect_contains("b", target = letters) # Fail
Expectation predicate for testing that a vector is fully contained within another vector
expect_in(current, target, ..., info = NA_character_)expect_in(current, target, ..., info = NA_character_)
current |
|
target |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_in()
Other in-condition expectation predicates:
expect_contains(),
expect_mapequal(),
expect_setequal()
expect_in(letters, target = rev(letters)) # Pass expect_in(letters, target = "b") # Fail expect_in("b", target = letters) # Passexpect_in(letters, target = rev(letters)) # Pass expect_in(letters, target = "b") # Fail expect_in("b", target = letters) # Pass
Expect Invisible
expect_invisible(current, ..., info = NA_character_)expect_invisible(current, ..., info = NA_character_)
current |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_invisible()
withVisible(), invisible()
Other visiblity expectation predicate:
expect_visible()
f <- function() invisible() expect_invisible(f()) # Pass g <- function() NULL expect_invisible(g()) # Failf <- function() invisible() expect_invisible(f()) # Pass g <- function() NULL expect_invisible(g()) # Fail
Expectation predicate for testing that the named sets of two vectors are equal
expect_mapequal( current, target, ..., info = NA_character_, tolerance = sqrt(x = .Machine$double.eps) )expect_mapequal( current, target, ..., info = NA_character_, tolerance = sqrt(x = .Machine$double.eps) )
current |
|
target |
|
... |
Ignored |
info |
|
tolerance |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_mapequal()
Other in-condition expectation predicates:
expect_contains(),
expect_in(),
expect_setequal()
(x <- `names<-`(letters, letters)) expect_mapequal(x, target = rev(x)) # Pass expect_mapequal(letters, target = c(b = "b")) # Fail expect_mapequal(c(b = "b"), target = x) # Fail(x <- `names<-`(letters, letters)) expect_mapequal(x, target = rev(x)) # Pass expect_mapequal(letters, target = c(b = "b")) # Fail expect_mapequal(c(b = "b"), target = x) # Fail
Expectation predicate for testing the names of an object
expect_named( current, target, ..., ignore.order = FALSE, ignore.case = FALSE, info = NA_character_ )expect_named( current, target, ..., ignore.order = FALSE, ignore.case = FALSE, info = NA_character_ )
current |
|
target |
|
... |
Ignored |
ignore.order |
|
ignore.case |
|
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_named()
(x <- c(a = 1L, b = 2L, c = 3L)) (y <- c(4L, 5L, 6L)) expect_named(x) # Pass expect_named(y) # Fail expect_named(x, target = NULL) # Fail expect_named(y, target = NULL) # Pass expect_named(x, target = c("a", "b", "c")) # Pass expect_named(y, target = c("a", "b", "c")) # Fail expect_named(x, target = c("b", "a", "c")) # Fail expect_named(x, target = c("b", "a", "c"), ignore.order = TRUE) # Pass expect_named(x, target = c("A", "B", "C")) # Fail expect_named(x, target = c("A", "B", "C"), ignore.case = TRUE) # Pass(x <- c(a = 1L, b = 2L, c = 3L)) (y <- c(4L, 5L, 6L)) expect_named(x) # Pass expect_named(y) # Fail expect_named(x, target = NULL) # Fail expect_named(y, target = NULL) # Pass expect_named(x, target = c("a", "b", "c")) # Pass expect_named(y, target = c("a", "b", "c")) # Fail expect_named(x, target = c("b", "a", "c")) # Fail expect_named(x, target = c("b", "a", "c"), ignore.order = TRUE) # Pass expect_named(x, target = c("A", "B", "C")) # Fail expect_named(x, target = c("A", "B", "C"), ignore.case = TRUE) # Pass
Expectation predicate for testing that a given function does not raise a condition
expect_no_condition( current, pattern = NULL, class = NULL, ..., info = NA_character_ )expect_no_condition( current, pattern = NULL, class = NULL, ..., info = NA_character_ )
current |
|
pattern |
|
class |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_no_condition()
Other condition expectation predicates:
expect_condition()
expect_no_condition("tomato") # Pass expect_no_condition(message("test")) # Fail expect_no_condition(message("test"), pattern = "test") # Fail expect_no_condition(message("test"), pattern = "tomato") # Pass expect_no_condition(message("test"), class = "message") # Fail expect_no_condition(message("test"), class = "error") # Pass expect_no_condition(message("test"), pattern = "test", class = "message") # Fail expect_no_condition(message("test"), pattern = "tomato", class = "message") # Pass expect_no_condition(message("test"), pattern = "test", class = "error") # Pass expect_no_condition(message("test"), pattern = "tomato", class = "error") # Passexpect_no_condition("tomato") # Pass expect_no_condition(message("test")) # Fail expect_no_condition(message("test"), pattern = "test") # Fail expect_no_condition(message("test"), pattern = "tomato") # Pass expect_no_condition(message("test"), class = "message") # Fail expect_no_condition(message("test"), class = "error") # Pass expect_no_condition(message("test"), pattern = "test", class = "message") # Fail expect_no_condition(message("test"), pattern = "tomato", class = "message") # Pass expect_no_condition(message("test"), pattern = "test", class = "error") # Pass expect_no_condition(message("test"), pattern = "tomato", class = "error") # Pass
Check that current is an S3 object that
inherits from class
expect_s3_class(current, class, ..., info = NA_character_, exact = FALSE)expect_s3_class(current, class, ..., info = NA_character_, exact = FALSE)
current |
|
class |
|
... |
Ignored |
info |
|
exact |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_s3_class()
Other typing expectation predicates:
expect_s4_class(),
expect_type()
expect_s3_class(data.frame(), "data.frame") # Pass expect_s3_class(1L, "integer") # Fail expect_s3_class(1L, NA) # Pass expect_s3_class(Matrix::Matrix(), "Matrix") # Fail expect_s3_class(Matrix::Matrix(), NA) # Passexpect_s3_class(data.frame(), "data.frame") # Pass expect_s3_class(1L, "integer") # Fail expect_s3_class(1L, NA) # Pass expect_s3_class(Matrix::Matrix(), "Matrix") # Fail expect_s3_class(Matrix::Matrix(), NA) # Pass
Check that current is an S4 object that is of class class
expect_s4_class(current, class, ..., info = NA_character_)expect_s4_class(current, class, ..., info = NA_character_)
current |
|
class |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_s4_class()
Other typing expectation predicates:
expect_s3_class(),
expect_type()
expect_s4_class(Matrix::Matrix(), "Matrix") # Pass expect_s4_class(data.frame(), "data.frame") # Fail expect_s4_class(data.frame(), NA) # Passexpect_s4_class(Matrix::Matrix(), "Matrix") # Pass expect_s4_class(data.frame(), "data.frame") # Fail expect_s4_class(data.frame(), NA) # Pass
Expectation predicate for testing that the sets of two vectors are equal
expect_setequal(current, target, ..., info = NA_character_)expect_setequal(current, target, ..., info = NA_character_)
current |
|
target |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_setequal()
Other in-condition expectation predicates:
expect_contains(),
expect_in(),
expect_mapequal()
expect_setequal(letters, target = rev(letters)) # Pass expect_setequal(letters, target = "b") # Fail expect_setequal("b", target = letters) # Failexpect_setequal(letters, target = rev(letters)) # Pass expect_setequal(letters, target = "b") # Fail expect_setequal("b", target = letters) # Fail
Check that typeof(current) is type
expect_type(current, type, ..., info = NA_character_)expect_type(current, type, ..., info = NA_character_)
current |
|
type |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_type()
Other typing expectation predicates:
expect_s3_class(),
expect_s4_class()
expect_type(1L, "integer") # Pass expect_type(1.0, "integer") # Failexpect_type(1L, "integer") # Pass expect_type(1.0, "integer") # Fail
Expect Visible
expect_visible(current, ..., info = NA_character_)expect_visible(current, ..., info = NA_character_)
current |
|
... |
Ignored |
info |
|
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_visible()
Other visiblity expectation predicate:
expect_invisible()
f <- function() invisible() expect_visible(f()) # Fail g <- function() NULL expect_visible(g()) # Passf <- function() invisible() expect_visible(f()) # Fail g <- function() NULL expect_visible(g()) # Pass
Unconditionally stop testing a tinytest test file, preventing
additional tests in the file from running without triggering a failure. This
is the low-level exit function for other skip_() functions in
tinyexpect
skip(message = "Skipping")skip(message = "Skipping")
message |
A message describing why the test file is being skipped |
If called within a tinytest test, triggers an exit
condition; otherwise, returns message
testthat equivalent:
testthat::skip()
Other "stop testing" functions:
skip_if_not_installed(),
skip_on_bioc(),
skip_on_ci(),
skip_on_covr(),
skip_on_cran(),
skip_on_os()
skip()skip()
Conditionally stop testing a tinytest test file if a required package is not available or not of a minimum required version
skip_if_not_installed(pkg, minimum_version = NULL, quietly = TRUE) exit_if_not_installed(pkg, minimum_version = NULL, quietly = TRUE)skip_if_not_installed(pkg, minimum_version = NULL, quietly = TRUE) exit_if_not_installed(pkg, minimum_version = NULL, quietly = TRUE)
pkg |
Name of package to check for |
minimum_version |
Optional minimum required version of |
quietly |
Attempt to find the package quietly; passed to
|
If called within a tinytest test and pkg is either
not installed or not at least minimum_version, triggers an exit
condition; otherwise, returns one of
A string saying that pkg is not installed
A string saying that pkg is installed, but not
at least minimum_version
NULL invisibly
tinyexpect provides both “skip_” and “exit_”
versions of “stop testing” functions due to the different philosophies
of tinytest and testthat; in testthat, tests
are encapsulated by test_that() to create smaller
testing units within a single test file. As such, if a series of tests need
to be passed over for some reason, it makes sense to “skip” a
test_that() block and move on to the next block
tinytest, however, treats each test file as a testing unit. Each
file in inst/tinytest is equivalent to a testthat
test_that() block; as such, if a series of tests need
to be passed over for some reason, it makes sense to “exit” a test
file and move on to the next file in inst/tinytest
In order to provide compatibility with users transitioning from
testthat to tinytest, and to provide continuity with the
tinytest philosophy, tinyexpect provides both skip_-
and exit_- prefixed “stop testing” functions that work
identically to one another
testthat equivalent:
testthat::skip_if_not_installed()
Other "stop testing" functions:
skip(),
skip_on_bioc(),
skip_on_ci(),
skip_on_covr(),
skip_on_cran(),
skip_on_os()
(pkg <- paste(sample(letters, size = 7L, replace = TRUE), collapse = "")) skip_if_not_installed(pkg) skip_if_not_installed("tinyexpect", minimum_version = "99.0.1")(pkg <- paste(sample(letters, size = 7L, replace = TRUE), collapse = "")) skip_if_not_installed(pkg) skip_if_not_installed("tinyexpect", minimum_version = "99.0.1")
Conditionally stop testing a tinytest test file if running on
the Bioconductor Build System. This is determined by checking if the
environment variable “IS_BIOC_BUILD_MACHINE” set and is
a non-FALSE value
skip_on_bioc() exit_on_bioc()skip_on_bioc() exit_on_bioc()
If called within a tinytest test running on the
Bioconductor Build System, triggers an exit condition; otherwise, either
a string saying “On Bioconductor” or NULL invisibly
testthat equivalent:
testthat::skip_on_bioc()
Other "stop testing" functions:
skip(),
skip_if_not_installed(),
skip_on_ci(),
skip_on_covr(),
skip_on_cran(),
skip_on_os()
withr::with_envvar(c(IS_BIOC_BUILD_MACHINE = "true"), skip_on_bioc())withr::with_envvar(c(IS_BIOC_BUILD_MACHINE = "true"), skip_on_bioc())
Conditionally stop testing a tinytest test file if running on CI.
This is determined by checking if the environment variable “CI”
set and is a non-FALSE value
skip_on_ci() exit_on_ci()skip_on_ci() exit_on_ci()
If called within a tinytest test running on CI, triggers
an exit condition; otherwise, either a string saying “On CI”
or NULL invisibly
tinyexpect provides both “skip_” and “exit_”
versions of “stop testing” functions due to the different philosophies
of tinytest and testthat; in testthat, tests
are encapsulated by test_that() to create smaller
testing units within a single test file. As such, if a series of tests need
to be passed over for some reason, it makes sense to “skip” a
test_that() block and move on to the next block
tinytest, however, treats each test file as a testing unit. Each
file in inst/tinytest is equivalent to a testthat
test_that() block; as such, if a series of tests need
to be passed over for some reason, it makes sense to “exit” a test
file and move on to the next file in inst/tinytest
In order to provide compatibility with users transitioning from
testthat to tinytest, and to provide continuity with the
tinytest philosophy, tinyexpect provides both skip_-
and exit_- prefixed “stop testing” functions that work
identically to one another
testthat equivalent:
testthat::skip_on_ci()
Other "stop testing" functions:
skip(),
skip_if_not_installed(),
skip_on_bioc(),
skip_on_covr(),
skip_on_cran(),
skip_on_os()
withr::with_envvar(c(CI = "true"), skip_on_ci())withr::with_envvar(c(CI = "true"), skip_on_ci())
Conditionally stop testing a tinytest test file if running
under covr. This is determined by checking if the environment
variable “R_COVR” set and is a non-FALSE value
skip_on_covr() exit_on_covr()skip_on_covr() exit_on_covr()
If called within a tinytest test running under
covr, triggers an exit condition; otherwise, either a
string saying “On covr” or NULL invisibly
tinyexpect provides both “skip_” and “exit_”
versions of “stop testing” functions due to the different philosophies
of tinytest and testthat; in testthat, tests
are encapsulated by test_that() to create smaller
testing units within a single test file. As such, if a series of tests need
to be passed over for some reason, it makes sense to “skip” a
test_that() block and move on to the next block
tinytest, however, treats each test file as a testing unit. Each
file in inst/tinytest is equivalent to a testthat
test_that() block; as such, if a series of tests need
to be passed over for some reason, it makes sense to “exit” a test
file and move on to the next file in inst/tinytest
In order to provide compatibility with users transitioning from
testthat to tinytest, and to provide continuity with the
tinytest philosophy, tinyexpect provides both skip_-
and exit_- prefixed “stop testing” functions that work
identically to one another
testthat equivalent:
testthat::skip_on_covr()
Other "stop testing" functions:
skip(),
skip_if_not_installed(),
skip_on_bioc(),
skip_on_ci(),
skip_on_cran(),
skip_on_os()
withr::with_envvar(c(R_COVR = "true"), skip_on_covr())withr::with_envvar(c(R_COVR = "true"), skip_on_covr())
Conditionally stop testing a tinytest test file if running under covr. This is determined by checking if
R is in a non-interactive session, and
the environment variable “NOT_CRAN” is unset or is not
a TRUE value
skip_on_cran() exit_on_cran()skip_on_cran() exit_on_cran()
If called within a tinytest test running on CRAN in a
non-interactive session, triggers an exit
condition; otherwise, either a string saying “On CRAN”
or NULL invisibly
tinyexpect provides both “skip_” and “exit_”
versions of “stop testing” functions due to the different philosophies
of tinytest and testthat; in testthat, tests
are encapsulated by test_that() to create smaller
testing units within a single test file. As such, if a series of tests need
to be passed over for some reason, it makes sense to “skip” a
test_that() block and move on to the next block
tinytest, however, treats each test file as a testing unit. Each
file in inst/tinytest is equivalent to a testthat
test_that() block; as such, if a series of tests need
to be passed over for some reason, it makes sense to “exit” a test
file and move on to the next file in inst/tinytest
In order to provide compatibility with users transitioning from
testthat to tinytest, and to provide continuity with the
tinytest philosophy, tinyexpect provides both skip_-
and exit_- prefixed “stop testing” functions that work
identically to one another
testthat equivalent:
testthat::skip_on_cran()
Other "stop testing" functions:
skip(),
skip_if_not_installed(),
skip_on_bioc(),
skip_on_ci(),
skip_on_covr(),
skip_on_os()
withr::with_envvar(c(NOT_CRAN = "false"), skip_on_cran())withr::with_envvar(c(NOT_CRAN = "false"), skip_on_cran())
Conditionally stop testing a tinytest test file if running under a given operating system and/or architecture
skip_on_os(os, arch = NULL) exit_on_os(os, arch = NULL)skip_on_os(os, arch = NULL) exit_on_os(os, arch = NULL)
os |
Operating system to not test on; choose one or more from:
The following OS designations are accepted as synonyms:
Pass |
arch |
Optional system architectures to not test on; note that this
only applies to operating systems present in |
If called within a tinytest test running under os
and potentially on an arch system, triggers an exit condition;
otherwise, returns one of
A string saying that the code is running under os
A string saying that the code is running under os on an
arch system
NULL invisibly
tinyexpect provides both “skip_” and “exit_”
versions of “stop testing” functions due to the different philosophies
of tinytest and testthat; in testthat, tests
are encapsulated by test_that() to create smaller
testing units within a single test file. As such, if a series of tests need
to be passed over for some reason, it makes sense to “skip” a
test_that() block and move on to the next block
tinytest, however, treats each test file as a testing unit. Each
file in inst/tinytest is equivalent to a testthat
test_that() block; as such, if a series of tests need
to be passed over for some reason, it makes sense to “exit” a test
file and move on to the next file in inst/tinytest
In order to provide compatibility with users transitioning from
testthat to tinytest, and to provide continuity with the
tinytest philosophy, tinyexpect provides both skip_-
and exit_- prefixed “stop testing” functions that work
identically to one another
testthat equivalent:
testthat::skip_on_os()
Tools for querying system OS and architecture:
Sys.info(), R.version[["arch"]]
Other "stop testing" functions:
skip(),
skip_if_not_installed(),
skip_on_bioc(),
skip_on_ci(),
skip_on_covr(),
skip_on_cran()
(system <- tolower(Sys.info()[["sysname"]])) skip_on_os(system) # Nothing happens if on a different OS (other <- sample(setdiff(c("windows", "mac", "linux", "solaris"), system), 1L)) skip_on_os(other) # System architectures can be used to fine-tune skips (sysarch <- R.version$arch) skip_on_os(system, arch = sysarch)(system <- tolower(Sys.info()[["sysname"]])) skip_on_os(system) # Nothing happens if on a different OS (other <- sample(setdiff(c("windows", "mac", "linux", "solaris"), system), 1L)) skip_on_os(other) # System architectures can be used to fine-tune skips (sysarch <- R.version$arch) skip_on_os(system, arch = sysarch)