Skip to content

Commit

Permalink
Merge pull request #307 from krlmlr/find-multi
Browse files Browse the repository at this point in the history
- `find_reporter()` (and also all high-level testing functions) support a vector of reporters. For more than one reporter, a `MultiReporter` is created (#307, @krlmlr).
  • Loading branch information
krlmlr committed Feb 19, 2016
2 parents c068dc4 + 3cde9b9 commit 1f43dc0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# testthat 0.11.0.9000

* `find_reporter()` (and also all high-level testing functions) support a vector of reporters. For more than one reporter, a `MultiReporter` is created (#307, @krlmlr).

* `with_reporter()` is used internally and gains new argument `start_end_reporter = TRUE` (@krlmlr, 355).

* `expect_success()` and `expect_failure()` are new expectations designed
Expand Down
13 changes: 12 additions & 1 deletion R/reporter-zzz.r
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,23 @@ with_reporter <- function(reporter, code, start_end_reporter = TRUE) {
#' Find reporter object given name or object.
#'
#' If not found, will return informative error message.
#' Pass a character vector to create a \code{\link{MultiReporter}} composed
#' of individual reporters.
#' Will return null if given NULL.
#'
#' @param reporter name of reporter
#' @param reporter name of reporter(s), or reporter object(s)
#' @keywords internal
find_reporter <- function(reporter) {
if (is.null(reporter)) return(NULL)

if (length(reporter) <= 1L) {
find_reporter_one(reporter)
} else {
MultiReporter$new(reporters = lapply(reporter, find_reporter_one))
}
}

find_reporter_one <- function(reporter) {
if (inherits(reporter, "Reporter")) return(reporter)

name <- reporter
Expand Down
4 changes: 3 additions & 1 deletion man/find_reporter.Rd

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

14 changes: 12 additions & 2 deletions tests/testthat/test-reporter.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ test_that("can locate reporter from name", {
expect_that(find_reporter("tap"), equals(TapReporter$new()))
expect_that(find_reporter("list"), equals(ListReporter$new()))
expect_that(find_reporter("multi"), equals(MultiReporter$new()))
expect_that(find_reporter(""), equals(Reporter$new()))
expect_equal(
find_reporter(c("summary", "stop")),
MultiReporter$new(
reporters = list(SummaryReporter$new(), StopReporter$new())))
expect_equal(
find_reporter(c("teamcity", "summary", "list")),
MultiReporter$new(
reporters = list(TeamcityReporter$new(), SummaryReporter$new(),
ListReporter$new())))

expect_that(find_reporter("blah"),
throws_error("Can not find test reporter blah"))
expect_error(find_reporter(c("summary", "blah")),
"Can not find test reporter blah")
})

0 comments on commit 1f43dc0

Please sign in to comment.