Skip to content

Commit

Permalink
Use user-specified stop_on_failure if provided. Fixes r-lib#2129
Browse files Browse the repository at this point in the history
  • Loading branch information
infotroph committed Oct 1, 2019
1 parent b722f80 commit 2348004
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ test <- function(pkg = ".", filter = NULL, ...) {

env <- new.env(parent = ns_env)

testthat_args <- list(test_path, filter = filter, env = env, stop_on_failure = FALSE, ... = ...)
testthat_args <- list(test_path, filter = filter, env = env, ... = ...)
testthat_args$stop_on_failure <- testthat_args$stop_on_failure %||% FALSE

if (packageVersion("testthat") >= "1.0.2.9000") { # 2.0.0
testthat_args <- c(testthat_args, load_helpers = FALSE)
} else if (packageVersion("testthat") > "1.0.2") {
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ test_that("TESTTHAT_PKG environment varaible is set", {
test("testTest", filter = "envvar", reporter = "stop")
expect_true(TRUE)
})

test_that("stop_on_failure set to FALSE if not provided", {
expect_output(test("testTestWithFailure", filter = "fail"), "Broken")
})

test_that("stop_on_failure passed on if provided", {
expect_output(test("testTestWithFailure", filter = "fail", stop_on_failure = FALSE), "Broken")
expect_error(test("testTestWithFailure", filter = "fail", stop_on_failure = TRUE))
})

test_that("stop_on_warning passed on if provided", {
expect_output(test("testTestWithFailure", filter = "warn", stop_on_warning = FALSE), "Beware!")
expect_error(test("testTestWithFailure", filter = "warn", stop_on_warning = TRUE))
})
10 changes: 10 additions & 0 deletions tests/testthat/testTestWithFailure/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Package: testTestWithFailure
Title: Tools to Make Developing R Code Easier
License: GPL-2
Description: Package description.
Author: Hadley <[email protected]>
Maintainer: Hadley <[email protected]>
Version: 0.1
Suggests:
testthat
RoxygenNote: 5.0.1
2 changes: 2 additions & 0 deletions tests/testthat/testTestWithFailure/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by roxygen2: do not edit by hand

1 change: 1 addition & 0 deletions tests/testthat/testTestWithFailure/R/dummy.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 4 additions & 0 deletions tests/testthat/testTestWithFailure/tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(testTest)

test_check("testTest")
5 changes: 5 additions & 0 deletions tests/testthat/testTestWithFailure/tests/testthat/test-fail.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
context("failure")

test_that("failing test", {
fail("Broken")
})
5 changes: 5 additions & 0 deletions tests/testthat/testTestWithFailure/tests/testthat/test-warn.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
context("warning")

test_that("warning from test", {
warning("Beware!")
})

0 comments on commit 2348004

Please sign in to comment.