File: reporter-fail.R

package info (click to toggle)
r-cran-testthat 3.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,452 kB
  • sloc: cpp: 9,261; ansic: 37; sh: 14; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 692 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#' Test reporter: fail at end.
#'
#' This reporter will simply throw an error if any of the tests failed. It is
#' best combined with another reporter, such as the
#' [SummaryReporter].
#'
#' @export
#' @family reporters
FailReporter <- R6::R6Class("FailReporter",
  inherit = Reporter,
  public = list(
    failed = FALSE,

    initialize = function(...) {
      self$capabilities$parallel_support <- TRUE
      super$initialize(...)
    },

    add_result = function(context, test, result) {
      self$failed <- self$failed || expectation_broken(result)
    },

    end_reporter = function() {
      if (self$failed) {
        stop("Failures detected.", call. = FALSE)
      }
    }
  )
)