-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck_coverage.R
More file actions
55 lines (45 loc) · 1.42 KB
/
check_coverage.R
File metadata and controls
55 lines (45 loc) · 1.42 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env Rscript
# Check test coverage for rSHUD package
cat("Checking test coverage for rSHUD...\n\n")
# Check if covr is installed
if (!requireNamespace("covr", quietly = TRUE)) {
cat("Installing covr package...\n")
install.packages("covr", repos = "https://cloud.r-project.org")
}
# Load covr
library(covr)
# Calculate package coverage
cat("Calculating coverage (this may take a few minutes)...\n")
cov <- package_coverage(type = "tests", quiet = FALSE)
# Print summary
cat("\n=== Coverage Summary ===\n")
print(cov)
# Get coverage percentage
pct <- percent_coverage(cov)
cat("\nOverall Coverage:", round(pct, 2), "%\n")
# Check if meets target
target <- 70
if (pct >= target) {
cat("✓ Coverage meets target of", target, "%\n")
} else {
cat("✗ Coverage below target of", target, "%\n")
cat(" Need to improve by:", round(target - pct, 2), "%\n")
}
# Show coverage by file
cat("\n=== Coverage by File ===\n")
file_cov <- coverage_to_list(cov)
for (file in names(file_cov)) {
file_pct <- file_cov[[file]]$coverage
cat(sprintf("%-40s %6.2f%%\n", basename(file), file_pct))
}
# Identify files with low coverage
cat("\n=== Files with Coverage < 50% ===\n")
low_cov_files <- names(file_cov)[sapply(file_cov, function(x) x$coverage < 50)]
if (length(low_cov_files) > 0) {
for (file in low_cov_files) {
cat(" -", basename(file), "\n")
}
} else {
cat(" None - all files have >= 50% coverage\n")
}
cat("\nDone!\n")