-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.R
More file actions
23 lines (20 loc) · 983 Bytes
/
Copy pathrun_tests.R
File metadata and controls
23 lines (20 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env Rscript
# 薄封装:每个 tests/test_*.R 在独立子进程(Rscript)里跑——与手动单跑行为一致,
# 天然隔离全局状态与 on.exit/tempdir 清理时机。仅聚合 + 门禁退出码,不改任何测试。
test_files <- sort(list.files("tests", pattern = "^test_.*\\.R$", full.names = TRUE))
if (length(test_files) == 0) stop("tests/ 下没有 test_*.R")
rscript <- file.path(R.home("bin"), "Rscript")
fails <- character()
for (f in test_files) {
out <- suppressWarnings(system2(rscript, shQuote(f), stdout = TRUE, stderr = TRUE))
code <- attr(out, "status")
ok <- is.null(code) || code == 0
cat(sprintf("%-6s %s\n", if (ok) "PASS" else "FAIL", basename(f)))
if (!ok) {
fails <- c(fails, basename(f))
cat(paste0(" | ", utils::tail(out, 8), "\n"))
}
}
cat(sprintf("\n== %d/%d passed, %d failed ==\n",
length(test_files) - length(fails), length(test_files), length(fails)))
if (length(fails) > 0) quit(status = 1)