-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a748bf7
commit e7bca36
Showing
5 changed files
with
165 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
test_that("Reading config options set with 'configure' yields the set value", { | ||
configure(flowr_host = "test.host", flowr_port = 1234, measure_time = TRUE, return_covr_result = TRUE) | ||
|
||
expect_equal(get_option("flowr_host"), "test.host") | ||
expect_equal(get_option("flowr_port"), 1234) | ||
expect_equal(get_option("return_covr_result"), TRUE) | ||
expect_equal(get_option("measure_time"), TRUE) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
test_that("empty tests have n:wo coverage", { | ||
file <- file_with_content("add <- function(a,b) a+b") | ||
test <- file_with_content("") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$coverage), 0) | ||
|
||
file <- file_with_content("") | ||
test <- file_with_content("") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$coverage), NaN) | ||
|
||
file <- file_with_content("") | ||
test <- file_with_content(" | ||
library(testthat) | ||
expect_true(TRUE) | ||
") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$coverage), NaN) | ||
}) | ||
|
||
test_that("test without (real) assertion has zero slicing coverage", { | ||
file <- file_with_content("add <- function(a,b) a+b") | ||
test <- file_with_content(" | ||
library(testthat) | ||
add(1,2) | ||
") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$coverage), 0) | ||
|
||
file <- file_with_content("add <- function(a,b) a+b") | ||
test <- file_with_content(" | ||
library(testthat) | ||
add(1,2) | ||
expect_true(TRUE) | ||
") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$coverage), 0) | ||
}) | ||
|
||
test_that("assertion in source file does is not sliced for", { | ||
file <- file_with_content(" | ||
add <- function(a,b){ | ||
testthat::expect_equal(1+2, 3) | ||
a+b | ||
} | ||
") | ||
test <- file_with_content("add(1,2)") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$coverage), 0) | ||
|
||
test <- file_with_content(" | ||
library(testthat) | ||
expect_equal(add(1,2), 3) | ||
") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$coverage), 50) | ||
}) | ||
|
||
test_that("slicing coverage can equal normal coverage", { | ||
file <- file_with_content("add <- function(a,b) a+b") | ||
test <- file_with_content(" | ||
library(testthat) | ||
expect_equal(add(1,2), 3) | ||
") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$covr), covr::percent_coverage(cov$coverage)) | ||
}) | ||
|
||
test_that("slicing coverage does not equal normal coverage for simple inputs", { | ||
file <- file_with_content(" | ||
add <- function(a,b) { | ||
x <<- 2; | ||
a + b | ||
}") | ||
test <- file_with_content(" | ||
library(testthat) | ||
expect_equal(add(1,2), 3) | ||
") | ||
|
||
cov <- file_coverage(file, test) | ||
expect(covr::percent_coverage(cov$covr) != covr::percent_coverage(cov$coverage), "coverage should not be equal") | ||
}) | ||
|
||
test_that("Coverage over multiple functions", { | ||
file <- file_with_content(" | ||
add <- function(a,b) { | ||
x <- add_helper(a) | ||
y <- add_helper(b) | ||
x + y | ||
} | ||
add_helper <- function(n) { | ||
x <- 0 | ||
while(x < n) { | ||
x <- x + 1 | ||
} | ||
return(x) | ||
} | ||
") | ||
test <- file_with_content(" | ||
library(testthat) | ||
expect_equal(add(1,2), 3) | ||
") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$coverage), 100) | ||
|
||
file <- file_with_content(" | ||
add <- function(a,b) { | ||
x <- add_helper(a) | ||
y <- add_helper(b) | ||
x + y | ||
} | ||
add_helper <- function(n) { | ||
x <- 0 | ||
while(x < n) { | ||
x <- x + 1 | ||
} | ||
return(x) | ||
} | ||
") | ||
test <- file_with_content(" | ||
library(testthat) | ||
expect_equal(add(1,2), 3) | ||
") | ||
|
||
cov <- file_coverage(file, test) | ||
expect_equal(covr::percent_coverage(cov$coverage), 100) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
test_that("we can find all pakage test files", { | ||
tmp_dir <- tempdir() | ||
dest_zip <- file.path(tmp_dir, "covr.zip") | ||
covr_dir <- file.path(tmp_dir, "covr-3.6.0") | ||
tryCatch(download.file( | ||
url = "https://github.com/r-lib/covr/archive/refs/tags/v3.6.0.zip", | ||
destfile = dest_zip, | ||
quiet = TRUE | ||
), error = function(e) skip("could not download package")) | ||
unzip(dest_zip, exdir = tmp_dir) | ||
|
||
sources <- get_pkg_source_files(covr_dir) | ||
tests <- get_pkg_test_files(covr_dir) | ||
|
||
expect_equal(length(sources$files), 27) | ||
expect_equal(length(tests$files), 73) | ||
}) |
This file was deleted.
Oops, something went wrong.