R/reporter-fail.R

#' @include reporter.R
NULL

#' 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,

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

    end_reporter = function() {
      if (self$failed) {
        stop("Failures detected.", call. = FALSE)
      }
    }
  )
)
r-lib/testthat documentation built on April 19, 2019, 7:05 p.m.