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)

Arguments

os

Operating system to not test on; choose one or more from:

  • windows

  • mac

  • linux

  • solaris

The following OS designations are accepted as synonyms:

  • darwin”: accepted in place of “mac

  • sunos”: accepted in place of “solaris

Pass TRUE to set os to all of the above; this is useful for limiting tests by architecture rather than OS/architecture combos

arch

Optional system architectures to not test on; note that this only applies to operating systems present in os

Value

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

“Skip” vs “Exit”

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

See also

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()

Examples

(system <- tolower(Sys.info()[["sysname"]]))
#> [1] "linux"
skip_on_os(system)
#> [1] "On Linux"

# Nothing happens if on a different OS
(other <- sample(setdiff(c("windows", "mac", "linux", "solaris"), system), 1L))
#> [1] "windows"
skip_on_os(other)

# System architectures can be used to fine-tune skips
(sysarch <- R.version$arch)
#> [1] "x86_64"
skip_on_os(system, arch = sysarch)
#> [1] "On Linux x86_64"