Skip to content

Commit 6099802

Browse files
authored
Handle syntax errors in parallel runs (#2172)
1 parent a7983dd commit 6099802

File tree

8 files changed

+57
-1
lines changed

8 files changed

+57
-1
lines changed

β€ŽNEWS.mdβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# testthat (development version)
22

3+
* Parallel testthat now does not ignore test files with syntax errors (#1360).
34
* `expect_lt()`, `expect_gt()`, and friends have a refined display that is more likely to display the correct number of digits and shows you the actual values compared.
45
* `describe()`, `it()`, and `test_that()` now have a shared stack of descriptions so that if you nest any inside of each other, any resulting failures will show you the full path.
56
* `describe()` now correctly scopes `skip()` (#2007).
67
* `ParallelProgressReporter` now respect `max_failures` (#1162).
78
* The last snapshot is no longer lost if the snapshot file is missing the final newline (#2092). It's easy to accidentally remove this because there are two trailing new lines in snapshot files and many editors will automatically remove if you touch the file.
89
* New `expect_r6_class()` (#2030).
9-
* `expect_*()` functions consistently and rigorously check their inputs (#1754).
10+
* `expect_*()` functions consistently and rigorously check their inputs (#1754).
1011
* `JunitReporter()` no longer fails with `"no applicable method for xml_add_child"` for warnings outside of tests (#1913). Additionally, warnings now save their backtraces.
1112
* `JunitReporter()` strips ANSI escapes in more placese (#1852, #2032).
1213
* `try_again()` is now publicised. The first argument is now the number of retries, not tries (#2050).

β€ŽR/parallel-taskq.Rβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ task_q <- R6::R6Class(
7878
private$tasks$state[[i]] <- "ready"
7979
msg <- NULL
8080
} else if (msg$code == PROCESS_DONE) {
81+
if (!is.null(msg$error)) {
82+
private$handle_error(msg, i)
83+
}
8184
private$tasks$state[[i]] <- "ready"
8285
} else if (msg$code %in% PROCESS_FAILURES) {
8386
private$handle_error(msg, i)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
test_that("error in parallel setup code", {
2+
skip_on_covr()
3+
withr::local_envvar(TESTTHAT_PARALLEL = "TRUE")
4+
err <- tryCatch(
5+
capture.output(suppressMessages(testthat::test_local(
6+
test_path("test-parallel", "syntax-error"),
7+
reporter = "summary"
8+
))),
9+
error = function(e) e
10+
)
11+
expect_s3_class(err, "testthat_process_error")
12+
# contains test file's name
13+
expect_match(conditionMessage(err), "test-error-1.R")
14+
# contains original error message
15+
expect_match(conditionMessage(err), "unexpected symbol")
16+
# contains the text of the syntax error
17+
expect_match(conditionMessage(err), "but this")
18+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Package: setup
2+
Title: What the Package Does (One Line, Title Case)
3+
Version: 0.0.0.9000
4+
Authors@R:
5+
person(given = "First",
6+
family = "Last",
7+
role = c("aut", "cre"),
8+
email = "[email protected]",
9+
comment = c(ORCID = "YOUR-ORCID-ID"))
10+
Description: What the package does (one paragraph).
11+
License: `use_mit_license()`, `use_gpl3_license()` or friends to
12+
pick a license
13+
Encoding: UTF-8
14+
LazyData: true
15+
Roxygen: list(markdown = TRUE)
16+
RoxygenNote: 7.1.1
17+
Suggests:
18+
testthat
19+
Config/testthat/parallel: true
20+
Config/testthat/edition: 3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated by roxygen2: do not edit by hand
2+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
library(testthat)
2+
library(ok)
3+
4+
test_check("ok")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test_that("this is good", {
2+
expect_equal(2 * 2, 4)
3+
})
4+
5+
but this is a syntax error!
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test_that("this fails", {
2+
expect_equal(Sys.getpid(), 0L)
3+
})

0 commit comments

Comments
Β (0)