@@ -9,75 +9,77 @@ create_gha_summary <- function(results) {
99 }
1010
1111 p <- function (... ) cat(... , file = out , append = TRUE )
12+ fmt_time <- function (x ) sprintf(" %.3fs" , x )
1213
13- # header
14- p(" <details>\n\n " )
15- p(" # Test results\n\n " )
16- p(" | FAIL | WARN | SKIP | PASS | Context | Test | Time |\n " )
17- p(" |-----:|-----:|-----:|-----:|:--------|:-----|:-----|\n " )
14+ results <- lapply(results , gha_summarize_test )
15+ totals <- list (
16+ n_fail = sum(vapply(results , " [[" , integer(1 ), " n_fail" )),
17+ n_warn = sum(vapply(results , " [[" , integer(1 ), " n_warn" )),
18+ n_skip = sum(vapply(results , " [[" , integer(1 ), " n_skip" )),
19+ n_ok = sum(vapply(results , " [[" , integer(1 ), " n_ok" )),
20+ real = sum(vapply(results , " [[" , double(1 ), " real" ))
21+ )
1822
19- # one line per test
20- per_test <- lapply(results , gha_file_summary , p = p )
23+ # summary
24+ p(" ### Test summary\n\n " )
25+ p(" | \u 274c FAIL | \u 26a0 WARN | \u 23ed\u fe0f SKIP | \u 2705 PASS | \u 23f1 Time |\n " )
26+ p(" |------------:|------------:|------------------:|------------:|:------------|\n " )
2127
22- # totals
23- totals <- lapply(do.call(rbind , per_test ), sum )
2428 p(paste0(
25- " |" , totals $ fail ,
26- " |" , totals $ warn ,
27- " |" , totals $ skip ,
28- " |" , totals $ ok ,
29- " |" , " Total" ,
30- " |" , " " ,
31- " |" , sprintf(" %.3f s" , totals $ time ),
29+ " |" , if (totals $ n_fail > 0 ) paste0(" \u 274c **" , totals $ n_fail , " **" ),
30+ " |" , if (totals $ n_warn > 0 ) paste0(" \u 26a0 **" , totals $ n_warn , " **" ),
31+ " |" , if (totals $ n_skip > 0 ) paste0(" \u 23ed\u fe0f **" , totals $ n_skip , " **" ),
32+ " |" , paste0(" \u 2705 **" , totals $ n_ok , " **" ),
33+ " |" , fmt_time(totals $ real ),
3234 " |\n "
3335 ))
3436
37+ # tests with issues
38+ p(" \n <details>\n\n " )
39+
40+ p(" ### Test details\n\n " )
41+ p(" | \u 274c FAIL | \u 26a0 WARN | \u 23ed\u fe0f SKIP | \u 2705 PASS | context | test | \u 23f1 Time |\n " )
42+ p(" |------------:|------------:|------------------:|------------:|:--------|:-----|:------------|\n " )
43+
44+ escape <- function (x ) {
45+ x <- gsub(" |" , " \\ |" , x , fixed = TRUE )
46+ x <- gsub(" \n " , " " , x , fixed = TRUE )
47+ x
48+ }
49+
50+ issues <- Filter(function (x ) length(x $ results ) != x $ n_ok , results )
51+ for (issue in issues ) {
52+ p(paste0(
53+ " |" , if (issue $ n_fail > 0 ) paste0(" \u 274c **" , issue $ n_fail , " **" ),
54+ " |" , if (issue $ n_warn > 0 ) paste0(" \u 26a0 **" , issue $ n_warn , " **" ),
55+ " |" , if (issue $ n_skip > 0 ) paste0(" \u 23ed\u fe0f **" , issue $ n_skip , " **" ),
56+ " |" , if (issue $ n_ok > 0 ) paste0(" \u 2705 **" , issue $ n_ok , " **" ),
57+ " |" , escape(context_name(issue $ file )),
58+ " |" , escape(issue $ test ),
59+ " |" , fmt_time(issue $ real ),
60+ " |\n "
61+ ))
62+ }
63+
3564 p(" \n </details>\n " )
3665
3766 invisible (results )
3867}
3968
40- gha_file_summary <- function (result , p ) {
69+ gha_summarize_test <- function (test ) {
4170
42- n_fail <- n_skip <- n_warn <- n_ok <- 0L
43- for (exp in result $ results ) {
71+ test $ n_fail <- test $ n_skip <- test $ n_warn <- test $ n_ok <- 0L
72+ for (exp in test $ results ) {
4473 if (expectation_broken(exp )) {
45- n_fail <- n_fail + 1L
74+ test $ n_fail <- test $ n_fail + 1L
4675 } else if (expectation_skip(exp )) {
47- n_skip <- n_skip + 1L
76+ test $ n_skip <- test $ n_skip + 1L
4877 } else if (expectation_warning(exp )) {
49- n_warn <- n_warn + 1L
78+ test $ n_warn <- test $ n_warn + 1L
5079 } else {
51- n_ok <- n_ok + 1L
80+ test $ n_ok <- test $ n_ok + 1L
5281 }
5382 }
5483
55- ctx <- context_name(result $ file )
56- time <- sprintf(" %.3f s" , result $ real )
57-
58- escape <- function (x ) {
59- x <- gsub(" |" , " \\ |" , x , fixed = TRUE )
60- x <- gsub(" \n " , " " , x , fixed = TRUE )
61- x
62- }
63-
64- p(paste0(
65- " |" , n_fail ,
66- " |" , n_warn ,
67- " |" , n_skip ,
68- " |" , n_ok ,
69- " |" , escape(ctx ),
70- " |" , escape(result $ test ),
71- " |" , time ,
72- " |\n "
73- ))
74-
75- data.frame (
76- stringsAsFactors = FALSE ,
77- fail = n_fail ,
78- skip = n_skip ,
79- warn = n_warn ,
80- ok = n_ok ,
81- time = result $ real
82- )
84+ test
8385}
0 commit comments