Skip to content

Commit c73f688

Browse files
committed
Handle interrupts in tests
I don't see any way to test this programmatically, so I've just been adding `Sys.sleep(10)` to a random test. Fixes #1464
1 parent 13e102e commit c73f688

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# testthat (development version)
22

3+
* Interrupting a test now prints the test name. This makes it easier to tell where a very slow test might be hanging (#1464)
34
* `expect_snapshot_value()` can now handle expressions that generate `-` (#1678) or zero length atomic vectors (#2042).
45
* `expect_matches()` failures should be a little easier to read (#2135).
56
* New `local_on_cran(TRUE)` allows you to simulate how your tests will run on CRAN (#2112).

R/test-that.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ test_code <- function(test, code, env, reporter, skip_on_empty = TRUE) {
178178
signalCondition(e)
179179
}
180180

181+
handle_interrupt <- function(e) {
182+
if (!is.null(test)) {
183+
cat("\n")
184+
cli::cli_inform(c("!" = "Interrupting test: {test}"))
185+
}
186+
}
187+
181188
test_env <- new.env(parent = env)
182189
old <- options(rlang_trace_top_env = test_env)[[1]]
183190
on.exit(options(rlang_trace_top_env = old), add = TRUE)
@@ -197,7 +204,8 @@ test_code <- function(test, code, env, reporter, skip_on_empty = TRUE) {
197204
skip = handle_skip,
198205
warning = handle_warning,
199206
message = handle_message,
200-
error = handle_error
207+
error = handle_error,
208+
interrupt = handle_interrupt
201209
),
202210
# some errors may need handling here, e.g., stack overflow
203211
error = handle_fatal,

0 commit comments

Comments
 (0)