tests/testthat/test-base.R

context("Base assertions")

test_that("any message is useful", {
  expect_equal(validate_that(any(TRUE, FALSE)), TRUE)
  
  x <- c(FALSE, FALSE)
  expect_equal(validate_that(any(x)), "No elements of x are true")
})

test_that("all message is useful", {
  expect_equal(validate_that(all(TRUE, TRUE)), TRUE)
  
  x <- c(FALSE, TRUE)
  expect_match(validate_that(all(x)), "Elements .* of x are not true")
})

test_that("custom message is printed", {
  expect_equal(validate_that(FALSE, msg = "Custom message"), "Custom message")
})

Try the assertthat package in your browser

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

assertthat documentation built on May 1, 2019, 10:25 p.m.