Skip to content

Commit 5170aab

Browse files
Added tests with comments
1 parent e4edd79 commit 5170aab

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/testthat/test-coverage.R

+33
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,39 @@ test_that("assertion in source file does is not sliced for", {
6363
expect_equal(covr::percent_coverage(cov$coverage), 50)
6464
})
6565

66+
test_that("covr does not consider code outside of functions", {
67+
file <- file_with_content("
68+
x <- 2
69+
y <- x + 2
70+
")
71+
test <- file_with_content("
72+
library(testthat)
73+
expect_true(x - 2 == 0)
74+
")
75+
76+
cov <- file_coverage(file, test)
77+
expect_equal(covr::percent_coverage(cov$covr), NaN)
78+
expect_equal(covr::percent_coverage(cov$coverage), NaN)
79+
})
80+
81+
test_that("commented coded does not matter", {
82+
file <- file_with_content("
83+
# This is a long comment to
84+
# test if comments are ignored
85+
# Here's a joke:
86+
# Why did the math book look so sad? Because it had too many problems!
87+
# HAHAHAHAHAHAHA
88+
add <- function(a,b) a+b
89+
")
90+
test <- file_with_content("
91+
library(testthat)
92+
expect_equal(add(1,2), 3)
93+
")
94+
95+
cov <- file_coverage(file, test)
96+
expect_equal(covr::percent_coverage(cov$coverage), 100)
97+
})
98+
6699
test_that("slicing coverage can equal normal coverage", {
67100
file <- file_with_content("add <- function(a,b) a+b")
68101
test <- file_with_content("

0 commit comments

Comments
 (0)