Skip to content

Commit

Permalink
Do not handle warnings when options("warn") >= 2 (#721)
Browse files Browse the repository at this point in the history
Pass through warnings when options("warn") >= 2
  • Loading branch information
yutannihilation authored and jimhester committed Mar 30, 2018
1 parent 6d30474 commit 5ed0bb1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

## Minor improvements and bug fixes

* Pass through warnings when `options(warn = 2)` is set (#721, @yutannihilation).

* `expect_lt()`, `expect_lte()`, `expect_gt()` `expect_gte()` now handle `Inf`
and `NA` arguments appropriately (#732).

Expand Down
4 changes: 4 additions & 0 deletions R/test-that.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ test_code <- function(test, code, env = test_env(), skip_on_empty = TRUE) {
invokeRestart("continue_test")
}
handle_warning <- function(e) {
# When options(warn) >= 2, a warning will be converted to an error.
# So, do not handle it here so that it will be handled by handle_error.
if (getOption("warn") >= 2) return()

handled <<- TRUE
e$expectation_calls <- frame_calls(11, 5)
register_expectation(e)
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-expect-error.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ test_that("generates informative failures", {
expect_error(stop("xxx"), regexp = "zzz", class = "zzz")
})
})

test_that("warnings are converted to errors when options('warn') >= 2", {
withr::with_options(
c(warn = 2),
expect_error(warning("foo"))
)
})

0 comments on commit 5ed0bb1

Please sign in to comment.