Skip to content

Commit 99d45a3

Browse files
dgkfjimhester
authored andcommitted
adding tests for 0 test case
1 parent b01aa0b commit 99d45a3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/testthat/test-record_tests.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ test_that("covr.record_tests: merging coverage objects appends tests", {
107107
})
108108

109109

110+
test_that("covr.record_tests: tests tally is pruned even when no tests are hit", {
111+
# "test" a function, but no code is executed and therefore no tests are logged
112+
fcode <- 'f <- function(x) { if (x) f(!x) else FALSE }'
113+
withr::with_options(c("covr.record_tests" = TRUE), cov <- code_coverage(fcode, "{ }"))
114+
115+
# expect that no tests were recorded, as no expressions evaluated f
116+
expect_null(attr(cov, "tests"))
117+
118+
# expect that a matrix was still produced by a counter and pruned to 0 rows
119+
expect_true(is.matrix(cov[[1L]]$tests))
120+
expect_equal(cov[[1L]]$value, 0L)
121+
expect_equal(nrow(cov[[1L]]$tests), 0L)
122+
})
123+
124+
110125
test_that("covr.record_tests: merging coverage test objects doesn't break default tests", {
111126
# recreate some ".counters" objects for testing
112127
.counter_1 <- list(

0 commit comments

Comments
 (0)