Skip to content

Commit

Permalink
Ensure that expect_no_error() and friends pass when appropriate
Browse files Browse the repository at this point in the history
Fixes #2037
  • Loading branch information
hadley committed Jan 8, 2025
1 parent 24ff6c0 commit 7f7ec73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion R/expect-no-condition.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ expect_no_ <- function(base_class,

capture <- function(code) {
try_fetch(
code,
{
code
NULL
},
!!base_class := function(cnd) {
if (!matcher(cnd)) {
return(zap())
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-expect-no-condition.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ test_that("expect_no_* conditions behave as expected", {
})

test_that("expect_no_* pass with pure code", {
expect_no_error(1)
expect_no_warning(1)
expect_no_message(1)
expect_no_condition(1)
expect_success(out <- expect_no_error(1))
expect_equal(out, 1)

expect_success(expect_no_warning(1))
expect_success(expect_no_message(1))
expect_success(expect_no_condition(1))
})

test_that("expect_no_* don't emit success when they fail", {
Expand Down

0 comments on commit 7f7ec73

Please sign in to comment.