Skip to content

Commit 858bd84

Browse files
Added tests for what we can't do
1 parent 1ba1b3b commit 858bd84

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/testthat/test-coverage.R

+51
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,54 @@ test_that("We can find all assertions", {
300300
})
301301
}
302302
})
303+
304+
test_that("code that's called by eval or do.call is not in the slice", {
305+
file <- file_with_content("
306+
do_the_add <- function(a,b) a+b
307+
add <- function(a,b) {
308+
x <- do.call('do_the_add', list(a, b))
309+
return(x)
310+
}
311+
")
312+
test <- file_with_content("
313+
library(testthat)
314+
expect_equal(add(1,2), 3)
315+
")
316+
317+
cov <- file_coverage(file, test)
318+
expect_equal(covr::percent_coverage(cov$coverage), 66.7, tolerance = 0.1)
319+
320+
file <- file_with_content("
321+
do_the_add <- function(a,b) a+b
322+
add <- function(a,b) {
323+
x <- eval(parse(text = 'do_the_add(a,b)'))
324+
return(x)
325+
}
326+
")
327+
test <- file_with_content("
328+
library(testthat)
329+
expect_equal(add(1,2), 3)
330+
")
331+
332+
cov <- file_coverage(file, test)
333+
expect_equal(covr::percent_coverage(cov$coverage), 66.7, tolerance = 0.1)
334+
})
335+
336+
test_that("flowr can't slice through objects", {
337+
file <- file_with_content("
338+
compex_calc_x <- function(x) x*2
339+
compex_calc_y <- function(x) x+1
340+
doit <- function(x) {
341+
x <- compex_calc_x(x)
342+
y <- compex_calc_y(x)
343+
return(list(x = x, y = y))
344+
}
345+
")
346+
test <- file_with_content("
347+
library(testthat)
348+
expect_false(is.null(doit(5)$x))
349+
")
350+
351+
cov <- file_coverage(file, test)
352+
expect_equal(covr::percent_coverage(cov$coverage), 100)
353+
})

0 commit comments

Comments
 (0)