@@ -63,6 +63,39 @@ test_that("assertion in source file does is not sliced for", {
63
63
expect_equal(covr :: percent_coverage(cov $ coverage ), 50 )
64
64
})
65
65
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
+
66
99
test_that(" slicing coverage can equal normal coverage" , {
67
100
file <- file_with_content(" add <- function(a,b) a+b" )
68
101
test <- file_with_content("
0 commit comments