From 574e249c8db2a3d99d2af91e1e91de0bed1ab35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 1 Jun 2022 11:52:37 +0200 Subject: [PATCH 01/18] PoC of markdown summary on GHA --- R/gha-summary.R | 80 +++++++++++++++++++++++++ R/parallel.R | 2 + R/test-files.R | 2 + tests/testthat/test-parallel-crash.R | 5 +- tests/testthat/test-parallel-outside.R | 5 +- tests/testthat/test-parallel-setup.R | 5 +- tests/testthat/test-parallel-startup.R | 5 +- tests/testthat/test-parallel-teardown.R | 5 +- tests/testthat/test-parallel.R | 5 +- tests/testthat/test-reporter-list.R | 5 ++ tests/testthat/test-snapshot-reporter.R | 2 + tests/testthat/test-teardown.R | 1 + tests/testthat/test-test-files.R | 25 ++++++-- 13 files changed, 137 insertions(+), 10 deletions(-) create mode 100644 R/gha-summary.R diff --git a/R/gha-summary.R b/R/gha-summary.R new file mode 100644 index 000000000..f948817e8 --- /dev/null +++ b/R/gha-summary.R @@ -0,0 +1,80 @@ + +create_gha_summary <- function(results) { + nope <- c("false", "no", "off", "n", "0", "nope", "nay") + if (tolower(Sys.getenv("TESTTHAT_GHA_SUMMARY")) %in% nope) { + return() + } + if ((out <- Sys.getenv("GITHUB_STEP_SUMMARY")) == "") { + return() + } + + p <- function(...) cat(..., file = out, append = TRUE) + + # header + p("# Test results\n\n") + p("| FAIL | WARN | SKIP | PASS | Context | Test | Time |\n") + p("|-----:|-----:|-----:|-----:|:--------|:-----|:-----|\n") + + # one line per test + per_test <- lapply(results, gha_file_summary, p = p) + + # totals + totals <- lapply(do.call(rbind, per_test), sum) + p(paste0( + "|", totals$fail, + "|", totals$warn, + "|", totals$skip, + "|", totals$ok, + "|", "Total", + "|", "", + "|", sprintf("%.3f s", totals$time), + "|\n" + )) + + invisible(results) +} + +gha_file_summary <- function(result, p) { + + n_fail <- n_skip <- n_warn <- n_ok <- 0L + for (exp in result$results) { + if (expectation_broken(exp)) { + n_fail <- n_fail + 1L + } else if (expectation_skip(exp)) { + n_skip <- n_skip + 1L + } else if (expectation_warning(exp)) { + n_warn <- n_warn + 1L + } else { + n_ok <- n_ok + 1L + } + } + + ctx <- context_name(result$file) + time <- sprintf("%.3f s", result$real) + + escape <- function(x) { + x <- gsub("|", "\\|", x, fixed = TRUE) + x <- gsub("\n", " ", x, fixed = TRUE) + x + } + + p(paste0( + "|", n_fail, + "|", n_warn, + "|", n_skip, + "|", n_ok, + "|", escape(ctx), + "|", escape(result$test), + "|", time, + "|\n" + )) + + data.frame( + stringsAsFactors = FALSE, + fail = n_fail, + skip = n_skip, + warn = n_warn, + ok = n_ok, + time = result$real + ) +} diff --git a/R/parallel.R b/R/parallel.R index c8621078a..3a3a3e14e 100644 --- a/R/parallel.R +++ b/R/parallel.R @@ -79,6 +79,8 @@ test_files_parallel <- function( } }) + create_gha_summary(reporters$list$get_results()) + test_files_check(reporters$list$get_results(), stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning diff --git a/R/test-files.R b/R/test-files.R index 2f846751e..0a8b645c4 100644 --- a/R/test-files.R +++ b/R/test-files.R @@ -204,6 +204,8 @@ test_files_serial <- function(test_dir, lapply(test_paths, test_one_file, env = env, wrap = wrap) ) + create_gha_summary(reporters$list$get_results()) + test_files_check(reporters$list$get_results(), stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning diff --git a/tests/testthat/test-parallel-crash.R b/tests/testthat/test-parallel-crash.R index 0201f1cfd..e377ce175 100644 --- a/tests/testthat/test-parallel-crash.R +++ b/tests/testthat/test-parallel-crash.R @@ -4,7 +4,10 @@ test_that("crash", { skip_on_cran() skip_on_covr() - withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) do <- function() { err <- NULL diff --git a/tests/testthat/test-parallel-outside.R b/tests/testthat/test-parallel-outside.R index 0c4ed4a3e..8dea0e9b5 100644 --- a/tests/testthat/test-parallel-outside.R +++ b/tests/testthat/test-parallel-outside.R @@ -1,6 +1,9 @@ test_that("error outside of test_that()", { - withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) err <- tryCatch( suppressMessages(testthat::test_local( test_path("test-parallel", "outside"), diff --git a/tests/testthat/test-parallel-setup.R b/tests/testthat/test-parallel-setup.R index eff1de715..1738a63ae 100644 --- a/tests/testthat/test-parallel-setup.R +++ b/tests/testthat/test-parallel-setup.R @@ -1,7 +1,10 @@ test_that("error in parallel setup code", { skip_on_covr() - withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) err <- tryCatch( suppressMessages(testthat::test_local( test_path("test-parallel", "setup"), diff --git a/tests/testthat/test-parallel-startup.R b/tests/testthat/test-parallel-startup.R index 6daf444af..f6fa3c1a6 100644 --- a/tests/testthat/test-parallel-startup.R +++ b/tests/testthat/test-parallel-startup.R @@ -1,7 +1,10 @@ test_that("startup error", { skip_on_covr() - withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) err <- tryCatch( suppressMessages(testthat::test_local( test_path("test-parallel", "startup"), diff --git a/tests/testthat/test-parallel-teardown.R b/tests/testthat/test-parallel-teardown.R index 9f0bcb089..8f2641ae9 100644 --- a/tests/testthat/test-parallel-teardown.R +++ b/tests/testthat/test-parallel-teardown.R @@ -1,7 +1,10 @@ test_that("teardown error", { skip("teardown errors are ignored") - withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) err <- tryCatch( suppressMessages(testthat::test_local( test_path("test-parallel", "teardown"), diff --git a/tests/testthat/test-parallel.R b/tests/testthat/test-parallel.R index 6026dae17..20c662d26 100644 --- a/tests/testthat/test-parallel.R +++ b/tests/testthat/test-parallel.R @@ -23,7 +23,10 @@ test_that("detect number of cpus to use", { }) test_that("ok", { - withr::local_envvar(c(TESTTHAT_PARALLEL = "TRUE")) + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) suppressMessages(ret <- test_local( test_path("test-parallel", "ok"), reporter = "silent", diff --git a/tests/testthat/test-reporter-list.R b/tests/testthat/test-reporter-list.R index 14dc35da5..9d89d7f25 100644 --- a/tests/testthat/test-reporter-list.R +++ b/tests/testthat/test-reporter-list.R @@ -1,6 +1,7 @@ # regression test: test_file() used to crash with a NULL reporter test_that("ListReporter with test_file and NULL reporter", { + withr::local_envvar(TESTTHAT_GHA_SUMMARY = "FALSE") test_file_path <- 'test-list-reporter/test-exercise-list-reporter.R' expect_error(test_file(test_path(test_file_path), reporter = NULL), NA) }) @@ -9,6 +10,7 @@ test_that("ListReporter with test_file and NULL reporter", { # of a test (test_that() call). # N.B: the exception here happens between two tests: "before" and "after" test_that("ListReporter - exception outside of test_that()", { + withr::local_envvar(TESTTHAT_GHA_SUMMARY = "FALSE") test_file_path <- 'test-list-reporter/test-exception-outside-tests.R' res <- test_file(test_path(test_file_path), reporter = NULL) @@ -31,6 +33,7 @@ test_that("ListReporter - exception outside of test_that()", { test_that("captures error if only thing in file", { + withr::local_envvar(TESTTHAT_GHA_SUMMARY = "FALSE") test_file_path <- 'test-list-reporter/test-only-error.R' res <- test_file(test_path(test_file_path), reporter = NULL) @@ -40,6 +43,7 @@ test_that("captures error if only thing in file", { # ListReporter on a "standard" test file: 2 contexts, passing, failing and crashing tests test_that("exercise ListReporter", { + withr::local_envvar(TESTTHAT_GHA_SUMMARY = "FALSE") test_file_path <- 'test-list-reporter/test-exercise-list-reporter.R' res <- test_file(test_path(test_file_path), reporter = NULL) expect_s3_class(res, "testthat_results") @@ -60,6 +64,7 @@ test_that("exercise ListReporter", { # bare expectations are ignored test_that("ListReporter and bare expectations", { + withr::local_envvar(TESTTHAT_GHA_SUMMARY = "FALSE") test_file_path <- 'test-list-reporter/test-bare-expectations.R' res <- test_file(test_path(test_file_path), reporter = NULL) diff --git a/tests/testthat/test-snapshot-reporter.R b/tests/testthat/test-snapshot-reporter.R index 85f698e58..878dc41bc 100644 --- a/tests/testthat/test-snapshot-reporter.R +++ b/tests/testthat/test-snapshot-reporter.R @@ -144,6 +144,7 @@ test_that("errors in test doesn't change snapshot", { }) test_that("skips and unexpected errors reset snapshots", { + withr::local_envvar(TESTTHAT_GHA_SUMMARY = "FALSE") regenerate <- FALSE if (regenerate) { @@ -166,6 +167,7 @@ test_that("skips and unexpected errors reset snapshots", { }) test_that("`expect_error()` can fail inside `expect_snapshot()`", { + withr::local_envvar(TESTTHAT_GHA_SUMMARY = "FALSE") out <- test_file( test_path("test-snapshot", "test-expect-condition.R"), reporter = NULL diff --git a/tests/testthat/test-teardown.R b/tests/testthat/test-teardown.R index 4adc396b9..a41d377e5 100644 --- a/tests/testthat/test-teardown.R +++ b/tests/testthat/test-teardown.R @@ -26,6 +26,7 @@ test_that("teardowns runs in order", { }) test_that("teardown run after tests complete", { + withr::local_envvar(TESTTHAT_GHA_SUMMARY = "FALSE") test_file(test_path("test-teardown/test-teardown.R"), "silent") expect_false(file.exists(test_path("test-teardown/teardown.txt"))) }) diff --git a/tests/testthat/test-test-files.R b/tests/testthat/test-test-files.R index d696266df..0b8b1b868 100644 --- a/tests/testthat/test-test-files.R +++ b/tests/testthat/test-test-files.R @@ -1,14 +1,20 @@ # test_dir() -------------------------------------------------------------- test_that("stops on failure", { - withr::local_envvar(TESTTHAT_PARALLEL = "FALSE") + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) expect_error( test_dir(test_path("test_dir"), reporter = "silent") ) }) test_that("runs all tests and records output", { - withr::local_envvar(TESTTHAT_PARALLEL = "FALSE") + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) res <- test_dir(test_path("test_dir"), reporter = "silent", stop_on_failure = FALSE) df <- as.data.frame(res) df$user <- df$system <- df$real <- df$result <- NULL @@ -27,7 +33,10 @@ test_that("complains if no files", { }) test_that("can control if failures generate errors", { - withr::local_envvar(TESTTHAT_PARALLEL = "FALSE") + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) test_error <- function(...) { test_dir(test_path("test-error"), reporter = "silent", ...) } @@ -37,7 +46,11 @@ test_that("can control if failures generate errors", { }) test_that("can control if warnings errors", { - withr::local_envvar(TESTTHAT_PARALLEL = "FALSE") + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) + test_warning <- function(...) { test_dir(test_path("test-warning"), reporter = "silent", ...) } @@ -49,6 +62,10 @@ test_that("can control if warnings errors", { # test_file --------------------------------------------------------------- test_that("can test single file", { + withr::local_envvar(c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + )) out <- test_file(test_path("test_dir/test-basic.R"), reporter = "silent") expect_length(out, 5) }) From fa7509803ffa2b0606fc272d74b7ad2d27e645f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 1 Jun 2022 12:34:33 +0200 Subject: [PATCH 02/18] No GHA summary in test_file() To avoid the tables from running test_file() in examples. Not the best solution. --- R/test-files.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/test-files.R b/R/test-files.R index 0a8b645c4..e7fc5e152 100644 --- a/R/test-files.R +++ b/R/test-files.R @@ -137,6 +137,8 @@ test_file <- function(path, reporter = default_compact_reporter(), package = NUL stop("`path` does not exist", call. = FALSE) } + withr::local_envvar(TESTTHAT_GHA_SUMMARY = "false") + test_files( test_dir = dirname(path), test_package = package, From 045e26a1505cf934c8e1a852bf91970ec2453933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 1 Jun 2022 12:39:14 +0200 Subject: [PATCH 03/18] Put whole GHA summary into a
--- R/gha-summary.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/gha-summary.R b/R/gha-summary.R index f948817e8..31d15f65a 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -11,6 +11,7 @@ create_gha_summary <- function(results) { p <- function(...) cat(..., file = out, append = TRUE) # header + p("
\n") p("# Test results\n\n") p("| FAIL | WARN | SKIP | PASS | Context | Test | Time |\n") p("|-----:|-----:|-----:|-----:|:--------|:-----|:-----|\n") @@ -31,6 +32,8 @@ create_gha_summary <- function(results) { "|\n" )) + p("
\n") + invisible(results) } From 0112c9ee8141e1b4145b674d004468fa6f1b1dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 1 Jun 2022 12:47:37 +0200 Subject: [PATCH 04/18] GHA summary: need empty line after
--- R/gha-summary.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/gha-summary.R b/R/gha-summary.R index 31d15f65a..213442cdb 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -11,7 +11,7 @@ create_gha_summary <- function(results) { p <- function(...) cat(..., file = out, append = TRUE) # header - p("
\n") + p("
\n\n") p("# Test results\n\n") p("| FAIL | WARN | SKIP | PASS | Context | Test | Time |\n") p("|-----:|-----:|-----:|-----:|:--------|:-----|:-----|\n") @@ -32,7 +32,7 @@ create_gha_summary <- function(results) { "|\n" )) - p("
\n") + p("\n
\n") invisible(results) } From 7481df421302d07e2d7d7cb0cc9060ad9d17c324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 1 Jun 2022 13:08:59 +0200 Subject: [PATCH 05/18] Fix tests Meant PARALLEL = FALSE --- tests/testthat/test-test-files.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-test-files.R b/tests/testthat/test-test-files.R index 0b8b1b868..53a0066b0 100644 --- a/tests/testthat/test-test-files.R +++ b/tests/testthat/test-test-files.R @@ -2,7 +2,7 @@ test_that("stops on failure", { withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_PARALLEL = "FALSE", TESTTHAT_GHA_SUMMARY = "FALSE" )) expect_error( @@ -12,7 +12,7 @@ test_that("stops on failure", { test_that("runs all tests and records output", { withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_PARALLEL = "FALSE", TESTTHAT_GHA_SUMMARY = "FALSE" )) res <- test_dir(test_path("test_dir"), reporter = "silent", stop_on_failure = FALSE) @@ -34,7 +34,7 @@ test_that("complains if no files", { test_that("can control if failures generate errors", { withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_PARALLEL = "FALSE", TESTTHAT_GHA_SUMMARY = "FALSE" )) test_error <- function(...) { @@ -47,7 +47,7 @@ test_that("can control if failures generate errors", { test_that("can control if warnings errors", { withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_PARALLEL = "FALSE", TESTTHAT_GHA_SUMMARY = "FALSE" )) @@ -63,7 +63,7 @@ test_that("can control if warnings errors", { test_that("can test single file", { withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_PARALLEL = "FALSE", TESTTHAT_GHA_SUMMARY = "FALSE" )) out <- test_file(test_path("test_dir/test-basic.R"), reporter = "silent") From 859be30dbabf2d945121741d658ed905e1779ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 1 Jun 2022 14:18:36 +0200 Subject: [PATCH 06/18] GHA summary: only issues --- R/gha-summary.R | 104 ++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/R/gha-summary.R b/R/gha-summary.R index 213442cdb..4a136785e 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -9,75 +9,77 @@ create_gha_summary <- function(results) { } p <- function(...) cat(..., file = out, append = TRUE) + fmt_time <- function(x) sprintf("%.3fs", x) - # header - p("
\n\n") - p("# Test results\n\n") - p("| FAIL | WARN | SKIP | PASS | Context | Test | Time |\n") - p("|-----:|-----:|-----:|-----:|:--------|:-----|:-----|\n") + results <- lapply(results, gha_summarize_test) + totals <- list( + n_fail = sum(vapply(results, "[[", integer(1), "n_fail")), + n_warn = sum(vapply(results, "[[", integer(1), "n_warn")), + n_skip = sum(vapply(results, "[[", integer(1), "n_skip")), + n_ok = sum(vapply(results, "[[", integer(1), "n_ok")), + real = sum(vapply(results, "[[", double(1), "real")) + ) - # one line per test - per_test <- lapply(results, gha_file_summary, p = p) + # summary + p("### Test summary\n\n") + p("| \u274c FAIL | \u26a0 WARN | \u23ed\ufe0f SKIP | \u2705 PASS | \u23f1 Time |\n") + p("|------------:|------------:|------------------:|------------:|:------------|\n") - # totals - totals <- lapply(do.call(rbind, per_test), sum) p(paste0( - "|", totals$fail, - "|", totals$warn, - "|", totals$skip, - "|", totals$ok, - "|", "Total", - "|", "", - "|", sprintf("%.3f s", totals$time), + "|", if (totals$n_fail > 0) paste0("\u274c **", totals$n_fail, "**"), + "|", if (totals$n_warn > 0) paste0("\u26a0 **", totals$n_warn, "**"), + "|", if (totals$n_skip > 0) paste0("\u23ed\ufe0f **", totals$n_skip, "**"), + "|", paste0("\u2705 **", totals$n_ok, "**"), + "|", fmt_time(totals$real), "|\n" )) + # tests with issues + p("\n
\n\n") + + p("### Test details\n\n") + p("| \u274c FAIL | \u26a0 WARN | \u23ed\ufe0f SKIP | \u2705 PASS | context | test | \u23f1 Time |\n") + p("|------------:|------------:|------------------:|------------:|:--------|:-----|:------------|\n") + + escape <- function(x) { + x <- gsub("|", "\\|", x, fixed = TRUE) + x <- gsub("\n", " ", x, fixed = TRUE) + x + } + + issues <- Filter(function(x) length(x$results) != x$n_ok, results) + for (issue in issues) { + p(paste0( + "|", if (issue$n_fail > 0) paste0("\u274c **", issue$n_fail, "**"), + "|", if (issue$n_warn > 0) paste0("\u26a0 **", issue$n_warn, "**"), + "|", if (issue$n_skip > 0) paste0("\u23ed\ufe0f **", issue$n_skip, "**"), + "|", if (issue$n_ok > 0) paste0("\u2705 **", issue$n_ok, "**"), + "|", escape(context_name(issue$file)), + "|", escape(issue$test), + "|", fmt_time(issue$real), + "|\n" + )) + } + p("\n
\n") invisible(results) } -gha_file_summary <- function(result, p) { +gha_summarize_test <- function(test) { - n_fail <- n_skip <- n_warn <- n_ok <- 0L - for (exp in result$results) { + test$n_fail <- test$n_skip <- test$n_warn <- test$n_ok <- 0L + for (exp in test$results) { if (expectation_broken(exp)) { - n_fail <- n_fail + 1L + test$n_fail <- test$n_fail + 1L } else if (expectation_skip(exp)) { - n_skip <- n_skip + 1L + test$n_skip <- test$n_skip + 1L } else if (expectation_warning(exp)) { - n_warn <- n_warn + 1L + test$n_warn <- test$n_warn + 1L } else { - n_ok <- n_ok + 1L + test$n_ok <- test$n_ok + 1L } } - ctx <- context_name(result$file) - time <- sprintf("%.3f s", result$real) - - escape <- function(x) { - x <- gsub("|", "\\|", x, fixed = TRUE) - x <- gsub("\n", " ", x, fixed = TRUE) - x - } - - p(paste0( - "|", n_fail, - "|", n_warn, - "|", n_skip, - "|", n_ok, - "|", escape(ctx), - "|", escape(result$test), - "|", time, - "|\n" - )) - - data.frame( - stringsAsFactors = FALSE, - fail = n_fail, - skip = n_skip, - warn = n_warn, - ok = n_ok, - time = result$real - ) + test } From 5c13a99fd2bb7f6cda0622fd5669293f10de38ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 1 Jun 2022 14:39:31 +0200 Subject: [PATCH 07/18] GHA summary: need space between test suites E.g. on multi-platform windows. --- R/gha-summary.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/gha-summary.R b/R/gha-summary.R index 4a136785e..be4e29c47 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -61,7 +61,7 @@ create_gha_summary <- function(results) { )) } - p("\n
\n") + p("\n
\n\n\n") invisible(results) } From 86479d8df19935eeef86afdc5c6591335f9efe30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 1 Jun 2022 14:42:47 +0200 Subject: [PATCH 08/18] GHA summary: try to keep Unicode in output --- R/gha-summary.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/gha-summary.R b/R/gha-summary.R index be4e29c47..ffa7e7355 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -8,6 +8,9 @@ create_gha_summary <- function(results) { return() } + out <- file(out, open = "wba", encoding = "UTF-8") + on.exit(close(out), add = TRUE) + p <- function(...) cat(..., file = out, append = TRUE) fmt_time <- function(x) sprintf("%.3fs", x) From 191147a5a37a1c29f6c106b38d3fdb9ea1179b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 1 Jun 2022 15:11:57 +0200 Subject: [PATCH 09/18] GHA summary: more UTF-8 tries on Windows --- R/gha-summary.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/gha-summary.R b/R/gha-summary.R index ffa7e7355..10c98096e 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -8,10 +8,14 @@ create_gha_summary <- function(results) { return() } - out <- file(out, open = "wba", encoding = "UTF-8") + out <- file(out, open = "a+b", encoding = "unknown") on.exit(close(out), add = TRUE) - p <- function(...) cat(..., file = out, append = TRUE) + p <- function(...) { + s <- paste0(...) + Encoding(s) <- "unknown" + cat(s, file = out, append = TRUE) + } fmt_time <- function(x) sprintf("%.3fs", x) results <- lapply(results, gha_summarize_test) From 861e1ff90bb397240d7cb0f10eca653d9eaf3cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 8 May 2024 21:01:25 +0200 Subject: [PATCH 10/18] Fix merge mistake --- tests/testthat/test-parallel.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-parallel.R b/tests/testthat/test-parallel.R index 4ff7d0f0f..305076bc9 100644 --- a/tests/testthat/test-parallel.R +++ b/tests/testthat/test-parallel.R @@ -27,7 +27,6 @@ test_that("ok", { TESTTHAT_PARALLEL = "TRUE", TESTTHAT_GHA_SUMMARY = "FALSE" )) - suppressMessages(ret <- test_local( capture.output(suppressMessages(ret <- test_local( test_path("test-parallel", "ok"), reporter = "summary", From 758d2ce1859101ac6f59846fc5ddb286a189355d Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 15 Aug 2025 07:57:48 -0500 Subject: [PATCH 11/18] Reduce duplication in parallel tests --- tests/testthat/helper.R | 20 ++++++++++++++++++++ tests/testthat/test-parallel-crash.R | 7 +------ tests/testthat/test-parallel-errors.R | 12 +++--------- tests/testthat/test-parallel-outside.R | 14 ++------------ tests/testthat/test-parallel-setup.R | 15 +++------------ tests/testthat/test-parallel-startup.R | 15 +++------------ tests/testthat/test-parallel-stdout.R | 3 +-- tests/testthat/test-parallel-teardown.R | 15 +++------------ 8 files changed, 36 insertions(+), 65 deletions(-) create mode 100644 tests/testthat/helper.R diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R new file mode 100644 index 000000000..5bded57b2 --- /dev/null +++ b/tests/testthat/helper.R @@ -0,0 +1,20 @@ +local_parallel_test_config <- function(frame = caller_env()) { + skip_on_covr() + withr::local_envvar( + c( + TESTTHAT_PARALLEL = "TRUE", + TESTTHAT_GHA_SUMMARY = "FALSE" + ), + .local_envir = frame + ) +} + +capture_parallel_error <- function(path) { + tryCatch( + capture.output(suppressMessages(testthat::test_local( + path, + reporter = "summary" + ))), + error = function(e) e + ) +} diff --git a/tests/testthat/test-parallel-crash.R b/tests/testthat/test-parallel-crash.R index 101b8dff2..7c8addc6e 100644 --- a/tests/testthat/test-parallel-crash.R +++ b/tests/testthat/test-parallel-crash.R @@ -1,13 +1,8 @@ test_that("crash", { + local_parallel_test_config() skip_on_cran() - skip_on_covr() skip_if_not(getRversion() >= "4.4.0") - withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", - TESTTHAT_GHA_SUMMARY = "FALSE" - )) - pkg <- test_path("test-parallel", "crash") err <- callr::r( function() { diff --git a/tests/testthat/test-parallel-errors.R b/tests/testthat/test-parallel-errors.R index 5d4180af5..f1535b743 100644 --- a/tests/testthat/test-parallel-errors.R +++ b/tests/testthat/test-parallel-errors.R @@ -1,13 +1,7 @@ test_that("error in parallel setup code", { - skip_on_covr() - withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") - err <- tryCatch( - capture.output(suppressMessages(testthat::test_local( - test_path("test-parallel", "syntax-error"), - reporter = "summary" - ))), - error = function(e) e - ) + local_parallel_test_config() + + err <- capture_parallel_error(test_path("test-parallel", "syntax-error")) expect_s3_class(err, "testthat_process_error") # contains test file's name expect_match(conditionMessage(err), "test-error-1.R") diff --git a/tests/testthat/test-parallel-outside.R b/tests/testthat/test-parallel-outside.R index 843398557..9467d8682 100644 --- a/tests/testthat/test-parallel-outside.R +++ b/tests/testthat/test-parallel-outside.R @@ -1,16 +1,6 @@ test_that("error outside of test_that()", { - skip_on_covr() - withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", - TESTTHAT_GHA_SUMMARY = "FALSE" - )) - err <- tryCatch( - capture.output(suppressMessages(testthat::test_local( - test_path("test-parallel", "outside"), - reporter = "summary" - ))), - error = function(e) e - ) + local_parallel_test_config() + err <- capture_parallel_error(test_path("test-parallel", "outside")) expect_match(err$message, "Test failures") }) diff --git a/tests/testthat/test-parallel-setup.R b/tests/testthat/test-parallel-setup.R index 9b8c5aecc..16d622f44 100644 --- a/tests/testthat/test-parallel-setup.R +++ b/tests/testthat/test-parallel-setup.R @@ -1,16 +1,7 @@ test_that("error in parallel setup code", { - skip_on_covr() - withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", - TESTTHAT_GHA_SUMMARY = "FALSE" - )) - err <- tryCatch( - capture.output(suppressMessages(testthat::test_local( - test_path("test-parallel", "setup"), - reporter = "summary" - ))), - error = function(e) e - ) + local_parallel_test_config() + + err <- capture_parallel_error(test_path("test-parallel", "setup")) expect_s3_class(err, "testthat_process_error") expect_match(conditionMessage(err), "Error in setup", fixed = TRUE) }) diff --git a/tests/testthat/test-parallel-startup.R b/tests/testthat/test-parallel-startup.R index 003922cf5..86826b6f7 100644 --- a/tests/testthat/test-parallel-startup.R +++ b/tests/testthat/test-parallel-startup.R @@ -1,16 +1,7 @@ test_that("startup error", { - skip_on_covr() - withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", - TESTTHAT_GHA_SUMMARY = "FALSE" - )) - err <- tryCatch( - capture.output(suppressMessages(testthat::test_local( - test_path("test-parallel", "startup"), - reporter = "summary" - ))), - error = function(e) e - ) + local_parallel_test_config() + + err <- capture_parallel_error(test_path("test-parallel", "startup")) expect_s3_class(err, "testthat_process_error") expect_match(conditionMessage(err), "This will fail", fixed = TRUE) }) diff --git a/tests/testthat/test-parallel-stdout.R b/tests/testthat/test-parallel-stdout.R index 35d19eebd..32826a431 100644 --- a/tests/testthat/test-parallel-stdout.R +++ b/tests/testthat/test-parallel-stdout.R @@ -1,6 +1,5 @@ test_that("stdout/stderr in parallel code", { - skip_on_covr() - withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") + local_parallel_test_config() assemble_msgs <- function(txt, test_name) { prefix <- paste0("> ", test_name, ": ") diff --git a/tests/testthat/test-parallel-teardown.R b/tests/testthat/test-parallel-teardown.R index 1a881a1e1..0bf32ff19 100644 --- a/tests/testthat/test-parallel-teardown.R +++ b/tests/testthat/test-parallel-teardown.R @@ -1,17 +1,8 @@ test_that("teardown error", { skip("teardown errors are ignored") - skip_on_covr() - withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", - TESTTHAT_GHA_SUMMARY = "FALSE" - )) - err <- tryCatch( - capture.output(suppressMessages(testthat::test_local( - test_path("test-parallel", "teardown"), - reporter = "summary" - ))), - error = function(e) e - ) + local_parallel_test_config() + + err <- capture_parallel_error(test_path("test-parallel", "teardown")) expect_s3_class(err, "testthat_process_error") expect_match(err$message, "Error in teardown", fixed = TRUE) }) From 20d86a52db4886d22c584e39c8d791b6b9a0b25c Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 15 Aug 2025 11:59:21 -0500 Subject: [PATCH 12/18] Supress another GHA report --- tests/testthat/test-parallel.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-parallel.R b/tests/testthat/test-parallel.R index 5c33f349c..6bb665188 100644 --- a/tests/testthat/test-parallel.R +++ b/tests/testthat/test-parallel.R @@ -62,8 +62,8 @@ test_that("fail", { }) test_that("snapshots", { - skip_on_covr() - withr::local_envvar(c(TESTTHAT_PARALLEL = "TRUE")) + local_parallel_test_config() + tmp <- withr::local_tempdir("testthat-snap-") file.copy(test_path("test-parallel", "snap"), tmp, recursive = TRUE) # we cannot run these with the silent reporter, because it is not From 121f64b8ac8960ba09ed7bbd5cb715078f2c4cd6 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 15 Aug 2025 12:33:23 -0500 Subject: [PATCH 13/18] Refactoring; drop emoji; add test --- R/gha-summary.R | 122 ++++++++++++++------------- tests/testthat/_snaps/gha-summary.md | 21 +++++ tests/testthat/test-gha-summary.R | 4 + 3 files changed, 89 insertions(+), 58 deletions(-) create mode 100644 tests/testthat/_snaps/gha-summary.md create mode 100644 tests/testthat/test-gha-summary.R diff --git a/R/gha-summary.R b/R/gha-summary.R index 10c98096e..c70c5d022 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -1,80 +1,58 @@ - create_gha_summary <- function(results) { - nope <- c("false", "no", "off", "n", "0", "nope", "nay") - if (tolower(Sys.getenv("TESTTHAT_GHA_SUMMARY")) %in% nope) { - return() - } - if ((out <- Sys.getenv("GITHUB_STEP_SUMMARY")) == "") { - return() - } - - out <- file(out, open = "a+b", encoding = "unknown") - on.exit(close(out), add = TRUE) - - p <- function(...) { - s <- paste0(...) - Encoding(s) <- "unknown" - cat(s, file = out, append = TRUE) - } - fmt_time <- function(x) sprintf("%.3fs", x) - results <- lapply(results, gha_summarize_test) totals <- list( n_fail = sum(vapply(results, "[[", integer(1), "n_fail")), n_warn = sum(vapply(results, "[[", integer(1), "n_warn")), n_skip = sum(vapply(results, "[[", integer(1), "n_skip")), - n_ok = sum(vapply(results, "[[", integer(1), "n_ok")), - real = sum(vapply(results, "[[", double(1), "real")) + n_ok = sum(vapply(results, "[[", integer(1), "n_ok")), + real = sum(vapply(results, "[[", double(1), "real")) ) - # summary - p("### Test summary\n\n") - p("| \u274c FAIL | \u26a0 WARN | \u23ed\ufe0f SKIP | \u2705 PASS | \u23f1 Time |\n") - p("|------------:|------------:|------------------:|------------:|:------------|\n") - - p(paste0( - "|", if (totals$n_fail > 0) paste0("\u274c **", totals$n_fail, "**"), - "|", if (totals$n_warn > 0) paste0("\u26a0 **", totals$n_warn, "**"), - "|", if (totals$n_skip > 0) paste0("\u23ed\ufe0f **", totals$n_skip, "**"), - "|", paste0("\u2705 **", totals$n_ok, "**"), - "|", fmt_time(totals$real), - "|\n" - )) - - # tests with issues - p("\n
\n\n") + # summary ----------------------------------------------------------------- + gha_summary_write("### Test summary") + gha_summary_write() + gha_summary_write("| FAIL | WARN | SKIP | PASS | Time |") + gha_summary_write("|-----:|-----:|-----:|-----:|:-----|") + gha_summary_write( + c("|", if (totals$n_fail > 0) totals$n_fail), + c("|", if (totals$n_warn > 0) totals$n_warn), + c("|", if (totals$n_skip > 0) totals$n_skip), + c("|", totals$n_ok), + c("|", num_exact(totals$real, 3), "|") + ) - p("### Test details\n\n") - p("| \u274c FAIL | \u26a0 WARN | \u23ed\ufe0f SKIP | \u2705 PASS | context | test | \u23f1 Time |\n") - p("|------------:|------------:|------------------:|------------:|:--------|:-----|:------------|\n") + # issue details ----------------------------------------------------------- + gha_summary_write() + gha_summary_write("
") + gha_summary_write() - escape <- function(x) { - x <- gsub("|", "\\|", x, fixed = TRUE) - x <- gsub("\n", " ", x, fixed = TRUE) - x - } + gha_summary_write("### Test details") + gha_summary_write() + gha_summary_write("| File | Test | FAIL | WARN | SKIP | PASS | Time |") + gha_summary_write("|:-----|:-----|-----:|-----:|-----:|-----:|:-----|") issues <- Filter(function(x) length(x$results) != x$n_ok, results) for (issue in issues) { - p(paste0( - "|", if (issue$n_fail > 0) paste0("\u274c **", issue$n_fail, "**"), - "|", if (issue$n_warn > 0) paste0("\u26a0 **", issue$n_warn, "**"), - "|", if (issue$n_skip > 0) paste0("\u23ed\ufe0f **", issue$n_skip, "**"), - "|", if (issue$n_ok > 0) paste0("\u2705 **", issue$n_ok, "**"), - "|", escape(context_name(issue$file)), - "|", escape(issue$test), - "|", fmt_time(issue$real), - "|\n" - )) + gha_summary_write( + c("|", issue$file), + c("|", md_escape(issue$test)), + c("|", if (totals$n_fail > 0) issue$n_fail), + c("|", if (totals$n_warn > 0) issue$n_warn), + c("|", if (totals$n_skip > 0) issue$n_skip), + c("|", issue$n_ok), + c("|", num_exact(issue$real, 3), "|") + ) } - - p("\n
\n\n\n") + gha_summary_write() + gha_summary_write("
") + gha_summary_write() invisible(results) } -gha_summarize_test <- function(test) { +# Helpers ---------------------------------------------------------------------- +gha_summarize_test <- function(test) { test$n_fail <- test$n_skip <- test$n_warn <- test$n_ok <- 0L for (exp in test$results) { if (expectation_broken(exp)) { @@ -90,3 +68,31 @@ gha_summarize_test <- function(test) { test } + +gha_path <- function() { + nope <- c("false", "no", "off", "n", "0", "nope", "nay") + if (tolower(Sys.getenv("TESTTHAT_GHA_SUMMARY")) %in% nope) { + return() + } + if ((out <- Sys.getenv("GITHUB_STEP_SUMMARY")) == "") { + return() + } + out +} + +gha_summary_write <- function(...) { + path <- gha_path() + if (is.null(path)) { + return() + } + + string <- paste0(c(..., "\n"), collapse = "") + Encoding(string) <- "unknown" + cat(string, file = path, append = TRUE) +} + +md_escape <- function(x) { + x <- gsub("|", "\\|", x, fixed = TRUE) + x <- gsub("\n", " ", x, fixed = TRUE) + x +} diff --git a/tests/testthat/_snaps/gha-summary.md b/tests/testthat/_snaps/gha-summary.md new file mode 100644 index 000000000..fc9dc4666 --- /dev/null +++ b/tests/testthat/_snaps/gha-summary.md @@ -0,0 +1,21 @@ +# multiplication works + + Code + create_gha_summary(list()) + Output + ### Test summary + + | FAIL | WARN | SKIP | PASS | Time | + |-----:|-----:|-----:|-----:|:-----| + ||||0|0.000| + +
+ + ### Test details + + | File | Test | FAIL | WARN | SKIP | PASS | Time | + |:-----|:-----|-----:|-----:|-----:|-----:|:-----| + +
+ + diff --git a/tests/testthat/test-gha-summary.R b/tests/testthat/test-gha-summary.R new file mode 100644 index 000000000..a959b6eb0 --- /dev/null +++ b/tests/testthat/test-gha-summary.R @@ -0,0 +1,4 @@ +test_that("multiplication works", { + local_mocked_bindings(gha_path = function() stdout()) + expect_snapshot(create_gha_summary(list())) +}) From f5b723c8dbbcf0edd1c2648f99875f9104d450d1 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 15 Aug 2025 13:59:45 -0500 Subject: [PATCH 14/18] Use 2 dp --- R/gha-summary.R | 15 +++++++++------ tests/testthat/_snaps/gha-summary.md | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/R/gha-summary.R b/R/gha-summary.R index c70c5d022..61963c4d4 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -18,7 +18,7 @@ create_gha_summary <- function(results) { c("|", if (totals$n_warn > 0) totals$n_warn), c("|", if (totals$n_skip > 0) totals$n_skip), c("|", totals$n_ok), - c("|", num_exact(totals$real, 3), "|") + c("|", num_exact(totals$real, 2), "|") ) # issue details ----------------------------------------------------------- @@ -40,7 +40,7 @@ create_gha_summary <- function(results) { c("|", if (totals$n_warn > 0) issue$n_warn), c("|", if (totals$n_skip > 0) issue$n_skip), c("|", issue$n_ok), - c("|", num_exact(issue$real, 3), "|") + c("|", num_exact(issue$real, 2), "|") ) } gha_summary_write() @@ -74,12 +74,15 @@ gha_path <- function() { if (tolower(Sys.getenv("TESTTHAT_GHA_SUMMARY")) %in% nope) { return() } - if ((out <- Sys.getenv("GITHUB_STEP_SUMMARY")) == "") { - return() - } - out + + stdout() + # if ((out <- Sys.getenv("GITHUB_STEP_SUMMARY")) == "") { + # return() + # } + # out } + gha_summary_write <- function(...) { path <- gha_path() if (is.null(path)) { diff --git a/tests/testthat/_snaps/gha-summary.md b/tests/testthat/_snaps/gha-summary.md index fc9dc4666..5121c78ae 100644 --- a/tests/testthat/_snaps/gha-summary.md +++ b/tests/testthat/_snaps/gha-summary.md @@ -7,7 +7,7 @@ | FAIL | WARN | SKIP | PASS | Time | |-----:|-----:|-----:|-----:|:-----| - ||||0|0.000| + ||||0|0.00|
From 2f35166d801bdc2dbc97e822d6d9eee5bf785e6e Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 15 Aug 2025 13:59:49 -0500 Subject: [PATCH 15/18] Quiet more tests --- tests/testthat/test-parallel.R | 18 +++++------------- tests/testthat/test-test-files.R | 5 ++++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/tests/testthat/test-parallel.R b/tests/testthat/test-parallel.R index ebbf14811..ca3cc4835 100644 --- a/tests/testthat/test-parallel.R +++ b/tests/testthat/test-parallel.R @@ -26,11 +26,7 @@ test_that("good error if bad option", { }) test_that("ok", { - skip_on_covr() - withr::local_envvar(c( - TESTTHAT_PARALLEL = "TRUE", - TESTTHAT_GHA_SUMMARY = "FALSE" - )) + local_parallel_test_config() capture.output(suppressMessages( ret <- test_local( test_path("test-parallel", "ok"), @@ -45,8 +41,7 @@ test_that("ok", { }) test_that("fail", { - skip_on_covr() - withr::local_envvar(c(TESTTHAT_PARALLEL = "TRUE")) + local_parallel_test_config() # we cannot run these with the silent reporter, because it is not # parallel compatible, and they'll not run in parallel capture.output(suppressMessages( @@ -85,9 +80,8 @@ test_that("snapshots", { }) test_that("new snapshots are added", { - skip_on_covr() - skip_on_cran() - withr::local_envvar(c(TESTTHAT_PARALLEL = "TRUE", CI = "false")) + local_parallel_test_config() + withr::local_envvar(CI = "false") tmp <- withr::local_tempdir("testthat-snap-") file.copy(test_path("test-parallel", "snap"), tmp, recursive = TRUE) @@ -142,10 +136,8 @@ test_that("snapshots are removed if test file has no snapshots", { }) test_that("snapshots are removed if test file is removed", { - skip_on_covr() - skip_on_cran() + local_parallel_test_config() - withr::local_envvar(c(TESTTHAT_PARALLEL = "TRUE")) withr::defer(unlink(tmp, recursive = TRUE)) dir.create(tmp <- tempfile("testthat-snap-")) file.copy(test_path("test-parallel", "snap"), tmp, recursive = TRUE) diff --git a/tests/testthat/test-test-files.R b/tests/testthat/test-test-files.R index cc689ae8a..5ea318bb5 100644 --- a/tests/testthat/test-test-files.R +++ b/tests/testthat/test-test-files.R @@ -29,7 +29,10 @@ test_that("runs all tests and records output", { }) test_that("complains if no files", { - withr::local_envvar(TESTTHAT_PARALLEL = "FALSE") + withr::local_envvar( + TESTTHAT_PARALLEL = "FALSE", + TESTTHAT_GHA_SUMMARY = "FALSE" + ) path <- withr::local_tempfile() dir.create(path) From 7c3e712ae7c47ce7e0d92d31046aa1618c5cffcd Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 15 Aug 2025 14:01:20 -0500 Subject: [PATCH 16/18] Use details summary --- R/gha-summary.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/gha-summary.R b/R/gha-summary.R index 61963c4d4..4c97421f4 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -24,9 +24,9 @@ create_gha_summary <- function(results) { # issue details ----------------------------------------------------------- gha_summary_write() gha_summary_write("
") - gha_summary_write() + gha_summary_write("Test details") - gha_summary_write("### Test details") + gha_summary_write("") gha_summary_write() gha_summary_write("| File | Test | FAIL | WARN | SKIP | PASS | Time |") gha_summary_write("|:-----|:-----|-----:|-----:|-----:|-----:|:-----|") From 5910801d5a1c526a9c50efd91ebee29cc599508a Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 15 Aug 2025 14:33:03 -0500 Subject: [PATCH 17/18] Revert testing code; update snapshot --- R/gha-summary.R | 9 ++++----- tests/testthat/_snaps/gha-summary.md | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/R/gha-summary.R b/R/gha-summary.R index 4c97421f4..7fc871fd5 100644 --- a/R/gha-summary.R +++ b/R/gha-summary.R @@ -75,11 +75,10 @@ gha_path <- function() { return() } - stdout() - # if ((out <- Sys.getenv("GITHUB_STEP_SUMMARY")) == "") { - # return() - # } - # out + if ((out <- Sys.getenv("GITHUB_STEP_SUMMARY")) == "") { + return() + } + out } diff --git a/tests/testthat/_snaps/gha-summary.md b/tests/testthat/_snaps/gha-summary.md index 5121c78ae..453f66259 100644 --- a/tests/testthat/_snaps/gha-summary.md +++ b/tests/testthat/_snaps/gha-summary.md @@ -10,8 +10,8 @@ ||||0|0.00|
+ Test details - ### Test details | File | Test | FAIL | WARN | SKIP | PASS | Time | |:-----|:-----|-----:|-----:|-----:|-----:|:-----| From 97ad7e40478560e55ffc8a133c61b25ea8e22c0d Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 15 Aug 2025 14:48:16 -0500 Subject: [PATCH 18/18] Silence more --- tests/testthat/test-parallel.R | 4 +--- tests/testthat/test-test-files.R | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-parallel.R b/tests/testthat/test-parallel.R index ca3cc4835..b3556e039 100644 --- a/tests/testthat/test-parallel.R +++ b/tests/testthat/test-parallel.R @@ -106,9 +106,7 @@ test_that("new snapshots are added", { }) test_that("snapshots are removed if test file has no snapshots", { - skip_on_covr() - skip_on_cran() - withr::local_envvar(c(TESTTHAT_PARALLEL = "TRUE")) + local_parallel_test_config() tmp <- withr::local_tempdir("testthat-snap-") file.copy(test_path("test-parallel", "snap"), tmp, recursive = TRUE) diff --git a/tests/testthat/test-test-files.R b/tests/testthat/test-test-files.R index 5ea318bb5..5c1bf792b 100644 --- a/tests/testthat/test-test-files.R +++ b/tests/testthat/test-test-files.R @@ -108,6 +108,11 @@ test_that("can filter test scripts", { # ---------------------------------------------------------------------- test_that("can configure `load_all()` (#1636)", { + withr::local_envvar( + TESTTHAT_PARALLEL = "FALSE", + TESTTHAT_GHA_SUMMARY = "FALSE" + ) + path <- test_path("testConfigLoadAll") args <- find_load_all_args(path)