Skip to content

Commit

Permalink
Merge pull request #394 from krlmlr/feature/error-in-message-prep
Browse files Browse the repository at this point in the history
Refactoring + enhanced tests
  • Loading branch information
hadley committed Mar 3, 2016
2 parents 7e6bb1d + 54cc863 commit 06f1a36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 3 additions & 5 deletions R/reporter-zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ with_reporter <- function(reporter, code, start_end_reporter = TRUE) {
reporter <- find_reporter(reporter)

old <- set_reporter(reporter)
on.exit(set_reporter(old))
on.exit(set_reporter(old), add = TRUE)

if (start_end_reporter) {
reporter$start_reporter()
# This will be executed *before* resetting the reporter, by design
on.exit(reporter$end_reporter(), add = TRUE)
}

force(code)

if (start_end_reporter) {
reporter$end_reporter()
}

invisible(reporter)
}

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-test-that.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@ test_that("errors are captured", {
expect_equal(length(reporter$expectations()), 1)
})

test_that("errors captured even when looking for messages", {
reporter <- with_reporter("silent", {
test_that("", expect_message(stop("a")))
})
expect_equal(length(reporter$expectations()), 1)
expect_true(expectation_error(reporter$expectations()[[1L]]))
})

test_that("errors captured even when looking for warnings", {
reporter <- with_reporter("silent", {
test_that("", expect_warning(stop()))
})
expect_equal(length(reporter$expectations()), 1)
expect_true(expectation_error(reporter$expectations()[[1L]]))
})

test_that("multiple failures captured even when looking for errors", {
Expand Down

0 comments on commit 06f1a36

Please sign in to comment.