|
1 | 1 | test_that("stdout/stderr in parallel code", { |
2 | 2 | skip_on_covr() |
3 | 3 | withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") |
4 | | - out <- capture.output(suppressMessages(testthat::test_local( |
5 | | - test_path("test-parallel", "stdout"), |
6 | | - reporter = "summary" |
7 | | - ))) |
8 | | - expect_match( |
9 | | - out, |
10 | | - "> test-stdout-2.R: This is a message!", |
11 | | - fixed = TRUE, |
12 | | - all = FALSE |
13 | | - ) |
14 | | - expect_match(out, "test-stdout-3.R: [1] 1 2 3", fixed = TRUE, all = FALSE) |
15 | 4 |
|
16 | | - out2 <- capture.output(suppressMessages(testthat::test_local( |
17 | | - test_path("test-parallel", "stdout"), |
18 | | - reporter = "progress" |
19 | | - ))) |
20 | | - expect_match( |
21 | | - out2, |
22 | | - "> test-stdout-2.R: This is a message!", |
23 | | - fixed = TRUE, |
24 | | - all = FALSE |
25 | | - ) |
26 | | - expect_match( |
27 | | - out2, |
28 | | - "test-stdout-3.R: [1] 1 2 3", |
29 | | - fixed = TRUE, |
30 | | - all = FALSE |
31 | | - ) |
| 5 | + assemble_msgs <- function(txt, test_name) { |
| 6 | + prefix <- paste0("> ", test_name, ": ") |
| 7 | + parts <- sub( |
| 8 | + prefix, |
| 9 | + "", |
| 10 | + grep(prefix, out, fixed = TRUE, value = TRUE), |
| 11 | + fixed = TRUE |
| 12 | + ) |
| 13 | + paste(parts, collapse = "") |
| 14 | + } |
| 15 | + |
| 16 | + for (reporter in c("summary", "progress")) { |
| 17 | + out <- capture.output(suppressMessages(testthat::test_local( |
| 18 | + test_path("test-parallel", "stdout"), |
| 19 | + reporter = reporter |
| 20 | + ))) |
| 21 | + msg2 <- assemble_msgs(out, "test-stdout-2.R") |
| 22 | + expect_match(msg2, "This is a message!", fixed = TRUE) |
| 23 | + msg3 <- assemble_msgs(out, "test-stdout-3.R") |
| 24 | + expect_match(msg3, "[1] 1 2 3", fixed = TRUE) |
| 25 | + } |
32 | 26 | }) |
0 commit comments