Skip to content

Need better framework for testing expectations #368

@hadley

Description

@hadley

e.g.

context("expect_output")

f <- function() NULL
g <- function() cat("!")

test_that("expect = NA checks for no output", {
  expect_error(expect_output(f(), NA), NA)
  expect_error(expect_output(g(), NA), "produced output")
})

test_that("expect = NULL checks for some output", {
  expect_error(expect_output(f(), NULL), "didn't produce output")
  expect_error(expect_output(g(), NULL), NA)
})

test_that("expect = string checks for match", {
  expect_error(expect_output(g(), "!"), NA)
  expect_error(expect_output(g(), "x"), "does not match 'x'")
})

And each expectation needs its own test file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions