From 7f7ec736a3243d4013600be55c42a44be5133085 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 8 Jan 2025 14:33:46 -0600 Subject: [PATCH] Ensure that `expect_no_error()` and friends pass when appropriate Fixes #2037 --- R/expect-no-condition.R | 5 ++++- tests/testthat/test-expect-no-condition.R | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/R/expect-no-condition.R b/R/expect-no-condition.R index 678ac178e..8d87b2aec 100644 --- a/R/expect-no-condition.R +++ b/R/expect-no-condition.R @@ -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()) diff --git a/tests/testthat/test-expect-no-condition.R b/tests/testthat/test-expect-no-condition.R index 58718e71e..cd66a5e12 100644 --- a/tests/testthat/test-expect-no-condition.R +++ b/tests/testthat/test-expect-no-condition.R @@ -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", {