File: test-parallel-stdout.R

package info (click to toggle)
r-cran-testthat 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,048 kB
  • sloc: cpp: 9,269; sh: 14; ansic: 14; makefile: 5
file content (26 lines) | stat: -rw-r--r-- 770 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
test_that("stdout/stderr in parallel code", {
  skip_on_covr()
  withr::local_envvar(TESTTHAT_PARALLEL = "TRUE")

  assemble_msgs <- function(txt, test_name) {
    prefix <- paste0("> ", test_name, ": ")
    parts <- sub(
      prefix,
      "",
      grep(prefix, out, fixed = TRUE, value = TRUE),
      fixed = TRUE
    )
    paste(parts, collapse = "")
  }

  for (reporter in c("summary", "progress")) {
    out <- capture.output(suppressMessages(testthat::test_local(
      test_path("test-parallel", "stdout"),
      reporter = reporter
    )))
    msg2 <- assemble_msgs(out, "test-stdout-2.R")
    expect_match(msg2, "This is a message!", fixed = TRUE)
    msg3 <- assemble_msgs(out, "test-stdout-3.R")
    expect_match(msg3, "[1]  1  2  3", fixed = TRUE)
  }
})