Skip to content

Commit 21e32d4

Browse files
authored
reat browser() as error (#1826)
1 parent 3b14f82 commit 21e32d4

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# testthat (development version)
22

3+
* `testthat` now sets the `_R_CHECK_BROWSER_NONINTERACTIVE_` environment variable
4+
when running tests. This should ensure that left-over `browser()` statements
5+
will trigger an error if encountered while running tests. This functionality
6+
is only enabled with R (>= 4.3.0). (#1825)
7+
38
# testthat 3.1.9
49

510
* New `expect_contains()` and `expect_in()` that works similarly to

R/local.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
#' cat("\n")
6666
#' })
6767
local_test_context <- function(.env = parent.frame()) {
68-
withr::local_envvar(TESTTHAT = "true", .local_envir = .env)
68+
withr::local_envvar("_R_CHECK_BROWSER_NONINTERACTIVE_" = "true", TESTTHAT = "true", .local_envir = .env)
6969
if (edition_get() >= 3) {
7070
local_reproducible_output(.env = .env)
7171
}

tests/testthat/test-browser.R

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
test_that("browser() usages are errors in tests", {
3+
skip_if(getRversion() < "4.3.0")
4+
if (!interactive())
5+
expect_error(browser())
6+
})

0 commit comments

Comments
 (0)