diff --git a/NEWS.md b/NEWS.md index 76645507b..47a92823a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # devtools (development version) +* `test_coverage_file()` now works when there is not a 1 to 1 correspondence + between test and source files (#2011). + * New `dev_sitrep()` function to return information about your development environment and diagnose common problems. The former functions `dr_devtools()` and `dr_github()` have been deprecated. (#1970) diff --git a/R/test.R b/R/test.R index 3dd422d8f..c9a8c3606 100644 --- a/R/test.R +++ b/R/test.R @@ -264,6 +264,8 @@ test_coverage_file <- function(file = find_active_file(), filter = TRUE, show_re }) ) + filter <- isTRUE(filter) && all(file.exists(source_files)) + if (isTRUE(filter)) { coverage <- coverage[covr::display_name(coverage) %in% source_files] } @@ -273,7 +275,11 @@ test_coverage_file <- function(file = find_active_file(), filter = TRUE, show_re attr(coverage, "package") <- pkg if (isTRUE(show_report)) { - covr::file_report(coverage) + if (isTRUE(filter)) { + covr::file_report(coverage) + } else { + covr::report(coverage) + } } invisible(coverage)