-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcoverage_skip.R
64 lines (55 loc) · 2.01 KB
/
coverage_skip.R
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
56
57
58
59
60
61
62
63
64
#' @title Run covr with failing tests
#' @description Run \code{\link[covr]{package_coverage}} ignoring failing tests from \code{\link[testthat]{test_dir}}.
#' @param test_path character, path to test directory, Default: 'tests/testthat'
#' @param test_skip data.frame, mapping of failing tests, PARAM_DESCRIPTION, Default: NULL
#' @return NULL
#' @details If test_skip is NULL then a new test_dir will be run internally checking
#' for failing tests.
#' @seealso
#' \code{\link[testthat]{test_dir}}
#' \code{\link[covr]{package_coverage}}
#' @rdname coverage_skip
#' @family utility
#' @export
#' @importFrom testthat test_dir
#' @importFrom covr package_coverage
coverage_skip <- function(
test_path = "tests/testthat",
test_skip = NULL) {
if (is.null(test_skip)) {
test_x <- testthat::test_dir(path = test_path)
test_m <- map_testthat(test_path)
test_x_long <- test_x |>
testthat_summary(type = "long")
test_skip <- test_x_long[test_x_long$status != "PASS", c("file", "test")]
test_skip$file <- gsub("#(.*?)$", "", basename(test_skip$file))
test_skip <- merge(test_skip, test_m)
}
test_skip_lines <- lapply(
split(test_skip, test_skip$file),
function(x) {
unlist(mapply(seq, from = x$line1, to = x$line2, SIMPLIFY = FALSE))
}
)
if (length(test_skip_lines) > 0) {
on.exit({
for (nx in names(test_skip_lines)) {
FILE <- file.path(test_path, nx)
TEST <- readLines(FILE, warn = FALSE)
LINES <- test_skip_lines[[nx]]
TEST[LINES] <- gsub("^#", "", TEST[LINES])
cat(TEST, file = file.path(test_path, nx), sep = "\n")
}
}, add = TRUE)
for (nx in names(test_skip_lines)) {
FILE <- file.path(test_path, nx)
TEST <- readLines(FILE, warn = FALSE)
LINES <- test_skip_lines[[nx]]
TEST[LINES] <- sprintf("#%s", TEST[LINES])
cat(TEST, file = file.path(test_path, nx), sep = "\n")
}
covr::package_coverage()
} else {
covr::package_coverage()
}
}