From 510e8261feb74b5d450e2894574aaff149c6e338 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 14 Aug 2025 13:30:48 -0500 Subject: [PATCH 1/2] Show all failure when hitting max failures in parallel mode Fixes #2217 --- R/reporter-progress.R | 38 ++++++++++++++++++---------- tests/testthat/_snaps/describe.md | 7 ----- tests/testthat/test-capture-output.R | 6 +++++ tests/testthat/test-watcher.R | 5 ++++ 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/R/reporter-progress.R b/R/reporter-progress.R index d7c273079..a7c1ccccb 100644 --- a/R/reporter-progress.R +++ b/R/reporter-progress.R @@ -231,6 +231,9 @@ ProgressReporter <- R6::R6Class( snapshotter$end_file() } + # Separate from the progress bar + self$cat_line() + self$cat_line() 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)}" @@ -462,22 +465,31 @@ ParallelProgressReporter <- R6::R6Class( }, end_file = function() { - fsts <- self$files[[self$file_name]] - time <- proc.time() - fsts$start_time + if (!self$is_full()) { + fsts <- self$files[[self$file_name]] + time <- proc.time() - fsts$start_time - # Workaround for https://github.com/rstudio/rstudio/issues/7649 - if (self$is_rstudio) { - self$cat_tight(strpad(self$cr(), self$width + 1)) # +1 for \r - } - self$show_status(complete = TRUE, time = time[[3]], pad = TRUE) - self$report_issues(fsts$issues) + # Workaround for https://github.com/rstudio/rstudio/issues/7649 + if (self$is_rstudio) { + self$cat_tight(strpad(self$cr(), self$width + 1)) # +1 for \r + } + self$show_status(complete = TRUE, time = time[[3]], pad = TRUE) + self$report_issues(fsts$issues) - self$files[[self$file_name]] <- NULL - if (length(self$files)) { - self$update(force = TRUE) - } + self$files[[self$file_name]] <- NULL + if (length(self$files)) { + self$update(force = TRUE) + } + } else { + self$cat_line() + + issues <- unlist( + map(self$files, \(x) x$issues$as_list()), + recursive = FALSE + ) + summary <- map_chr(issues, issue_summary) + self$cat_tight(paste(summary, collapse = "\n\n")) - if (self$is_full()) { self$report_full() } }, diff --git a/tests/testthat/_snaps/describe.md b/tests/testthat/_snaps/describe.md index 45a217506..31f628a73 100644 --- a/tests/testthat/_snaps/describe.md +++ b/tests/testthat/_snaps/describe.md @@ -1,10 +1,3 @@ -# snapshot tests in describe - - Code - 1 + 1 - Output - [1] 2 - # snapshot tests in describe / and in it Code diff --git a/tests/testthat/test-capture-output.R b/tests/testthat/test-capture-output.R index 32ecdf078..3e8be4de1 100644 --- a/tests/testthat/test-capture-output.R +++ b/tests/testthat/test-capture-output.R @@ -1,3 +1,9 @@ +test_that("fails", { + for (i in 1:5) { + test_that(paste0(i), fail()) + } +}) + test_that("multiplication works", { utf8 <- "M\u00e4chler" latin1 <- "M\xe4chler" diff --git a/tests/testthat/test-watcher.R b/tests/testthat/test-watcher.R index 328c91286..329e2951c 100644 --- a/tests/testthat/test-watcher.R +++ b/tests/testthat/test-watcher.R @@ -1,3 +1,8 @@ +test_that("fails", { + for (i in 1:5) { + test_that(paste0(i), fail()) + } +}) test_that("compare state works correctly", { loc <- withr::local_tempfile(pattern = "watcher") dir.create(loc) From 76de57e5c03e00568294c1ad5d96c34d5c05c15e Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 14 Aug 2025 13:47:24 -0500 Subject: [PATCH 2/2] Polishing --- R/reporter-progress.R | 6 ++++-- tests/testthat/_snaps/reporter-progress.md | 9 +++++---- tests/testthat/test-capture-output.R | 6 ------ tests/testthat/test-watcher.R | 5 ----- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/R/reporter-progress.R b/R/reporter-progress.R index a7c1ccccb..984b96526 100644 --- a/R/reporter-progress.R +++ b/R/reporter-progress.R @@ -233,9 +233,8 @@ ProgressReporter <- R6::R6Class( # Separate from the progress bar self$cat_line() - self$cat_line() stop_reporter(c( - "Maximum number of failures exceeded; quitting at end of file.", + "Maximum number of failures exceeded; quitting.", i = "Increase this number with (e.g.) {.run testthat::set_max_fails(Inf)}" )) }, @@ -481,7 +480,9 @@ ParallelProgressReporter <- R6::R6Class( self$update(force = TRUE) } } else { + self$update(force = TRUE) self$cat_line() + self$rule() issues <- unlist( map(self$files, \(x) x$issues$as_list()), @@ -490,6 +491,7 @@ ParallelProgressReporter <- R6::R6Class( summary <- map_chr(issues, issue_summary) self$cat_tight(paste(summary, collapse = "\n\n")) + self$cat_line() self$report_full() } }, diff --git a/tests/testthat/_snaps/reporter-progress.md b/tests/testthat/_snaps/reporter-progress.md index af5ed43d0..d7c1f1447 100644 --- a/tests/testthat/_snaps/reporter-progress.md +++ b/tests/testthat/_snaps/reporter-progress.md @@ -131,7 +131,8 @@ `actual`: FALSE `expected`: TRUE -------------------------------------------------------------------------------- - Maximum number of failures exceeded; quitting at end of file. + + Maximum number of failures exceeded; quitting. i Increase this number with (e.g.) `testthat::set_max_fails(Inf)` # can fully suppress incremental updates @@ -564,7 +565,7 @@ v | F W S OK | Context - [ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ] Starting up... - x | 11 0 | reporters/fail-many + \ [ FAIL 11 | WARN 0 | SKIP 0 | PASS 0 ] @ reporters/fail-many -------------------------------------------------------------------------------- Failure ('reporters/fail-many.R:3:5'): Example FALSE (`actual`) is not equal to TRUE (`expected`). @@ -631,8 +632,8 @@ `actual`: FALSE `expected`: TRUE - -------------------------------------------------------------------------------- - Maximum number of failures exceeded; quitting at end of file. + + Maximum number of failures exceeded; quitting. i Increase this number with (e.g.) `testthat::set_max_fails(Inf)` diff --git a/tests/testthat/test-capture-output.R b/tests/testthat/test-capture-output.R index 3e8be4de1..32ecdf078 100644 --- a/tests/testthat/test-capture-output.R +++ b/tests/testthat/test-capture-output.R @@ -1,9 +1,3 @@ -test_that("fails", { - for (i in 1:5) { - test_that(paste0(i), fail()) - } -}) - test_that("multiplication works", { utf8 <- "M\u00e4chler" latin1 <- "M\xe4chler" diff --git a/tests/testthat/test-watcher.R b/tests/testthat/test-watcher.R index 329e2951c..328c91286 100644 --- a/tests/testthat/test-watcher.R +++ b/tests/testthat/test-watcher.R @@ -1,8 +1,3 @@ -test_that("fails", { - for (i in 1:5) { - test_that(paste0(i), fail()) - } -}) test_that("compare state works correctly", { loc <- withr::local_tempfile(pattern = "watcher") dir.create(loc)