inst/tinytest/test_call.R

if (interactive()) {
  pkgload::load_all()
  library("tinytest")
}


result <- call_conditionally(get_package_version,
  condition = TRUE,
  args = list(x = "fritools2"),
  fallback = "0.0"
)
expectation <- get_package_version("fritools2")
expect_identical(result, expectation)
call_conditionally(get_package_version,
  condition = FALSE,
  args = list(x = "fritools2"),
  fallback = "0.0"
)
result <- call_conditionally(get_package_version,
  condition = FALSE,
  args = list(x = "fritools2"),
  fallback = "0.0"
)
expectation <- "0.0"
expect_identical(result, expectation)
result <- call_conditionally(get_package_version,
  condition = TRUE,
  args = list(x = "not_there"),
  harden = TRUE,
  fallback = "-1"
)
expectation <- "-1"
expect_identical(result, expectation)

expect_error(call_conditionally(get_package_version,
  condition = TRUE,
  args = list(x = "not_there"),
  harden = FALSE,
  fallback = "-1"
))

Try the fritools2 package in your browser

Any scripts or data that you put into this service are public.

fritools2 documentation built on July 9, 2023, 7:07 p.m.