Skip to content

Commit 6fd4371

Browse files
committed
Add tests for stdout/stderr from parallel workers
1 parent 602fc60 commit 6fd4371

File tree

9 files changed

+54
-3
lines changed

9 files changed

+54
-3
lines changed

β€Žtests/testthat/test-bare.Rβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ stopifnot(
1616
)
1717

1818
test_that("output", {
19-
message("hello!")
2019
expect_true(TRUE)
2120
})

β€Žtests/testthat/test-describe.Rβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,4 @@ describe("describe", {
5050
it("should not be possible to access variables from other specs (2)", {
5151
expect_false(exists("some_test_var"))
5252
})
53-
withr::local_options(width = 60)
54-
print(1:100)
5553
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
test_that("stdout/stderr in parallel code", {
2+
skip_on_covr()
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_true("> test-stdout-2.R: This is a message!" %in% out)
9+
expect_true(any(grepl("test-stdout-3.R: [1] 1 2 3", out, fixed = TRUE)))
10+
11+
out2 <- capture.output(suppressMessages(testthat::test_local(
12+
test_path("test-parallel", "stdout"),
13+
reporter = "progress"
14+
)))
15+
expect_true("> test-stdout-2.R: This is a message!" %in% out2)
16+
expect_true(any(grepl("test-stdout-3.R: [1] 1 2 3", out2, fixed = TRUE)))
17+
})
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test_that("this is good", {
2+
expect_equal(2 * 2, 4)
3+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_that("this messages", {
2+
message("This is a message!")
3+
expect_true(TRUE)
4+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_that("this prints and skips", {
2+
print(1:30)
3+
skip(paste("This is", Sys.getpid()))
4+
})

0 commit comments

Comments
Β (0)