Skip to content

Commit

Permalink
Clickable advice for setting max number of failures
Browse files Browse the repository at this point in the history
Fixes #1628
  • Loading branch information
hadley committed Sep 20, 2022
1 parent d3567be commit 27b597e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Depends:
Imports:
brio,
callr (>= 3.5.1),
cli (>= 3.3.0),
cli (>= 3.4.0),
desc,
digest,
ellipsis (>= 0.2.0),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export(not)
export(prints_text)
export(quasi_label)
export(run_cpp_tests)
export(set_max_fails)
export(set_reporter)
export(setup)
export(show_failure)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# testthat (development version)

* New `set_max_fails()` helper to make it easier to set the maximum number of
failures before stopping the test suite. And the advice to set to Inf is
now clickable (#1628).

* Fixed a warning in R >=4.2.0 on Windows that occurred when using the C++
testing infrastructure that testthat provides (#1672).

Expand Down
19 changes: 16 additions & 3 deletions R/reporter-progress.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ ProgressReporter <- R6::R6Class("ProgressReporter",
snapshotter$end_file()
}

stop_reporter(paste0(
"Maximum number of failures exceeded; quitting at end of file.\n",
"Increase this number with (e.g.) `Sys.setenv('TESTTHAT_MAX_FAILS' = Inf)`"
stop_reporter(c(
"Maximum number of failures exceeded; quitting at end of file.",
i = "Increase this number with (e.g.) {.run testthat::set_max_fails(Inf)}"
))
}
},
Expand Down Expand Up @@ -540,3 +540,16 @@ skip_bullets <- function(skips) {
tbl <- table(skips)
paste0(cli::symbol$bullet, " ", names(tbl), " (", tbl, ")")
}


#' Set maximum number of test failures before aborting the run
#'
#' This sets the `TESTTHAT_MAX_FAILS` env var which will affect both the
#' current R process and any processes launched from it.
#'
#' @param n Maximum number of failures allowed.
#' @export
#' @keywords internal
set_max_fails <- function(n) {
Sys.setenv('TESTTHAT_MAX_FAILS' = n)
}
2 changes: 1 addition & 1 deletion R/reporter-zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ with_reporter <- function(reporter, code, start_end_reporter = TRUE) {

stop_reporter <- function(message) {
signal(message, "testthat_abort_reporter")
abort(message)
cli::cli_abort(message, error_call = NULL)
}

#' Find reporter object given name or object.
Expand Down
16 changes: 16 additions & 0 deletions man/set_max_fails.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 27b597e

Please sign in to comment.