tests/testthat/helper-expectations.R

contains <- function(str, x) {
  grepl(x, str, fixed=TRUE)
}

readFile <- function(file) {
  paste(readLines(file), collapse="")
}

expectContains <- function(name, str) {
  expect(contains(name, str), paste(name, "does not contain", str))
}

refuteContains <- function(name, str) {
  expect(!contains(name, str), paste(name, "contains", str))
}

expectFile <- function(name) {
  expect(file.exists(name), paste(name, "does not exist"))
}

expectFileContains <- function(name, str) {
  expectContains(readFile(name), str)
}

refuteFileContains <- function(name, str) {
  refuteContains(readFile(name), str)
}

Try the jetpack package in your browser

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

jetpack documentation built on Oct. 31, 2022, 5:07 p.m.