Skip to content

Commit

Permalink
Add covr helper (#1635)
Browse files Browse the repository at this point in the history
* Add test_coverage helper

Fixes #1628
  • Loading branch information
hadley authored Oct 21, 2017
1 parent dd5300c commit 0d99183
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export(submit_cran)
export(system_check)
export(system_output)
export(test)
export(test_coverage)
export(uninstall)
export(unload)
export(update_packages)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# devtools 1.13.3.9000

* New `test_coverage()` provides helper to compute test coverage using covr
(#1628).

* `build_win()` has been renamed to `check_win_release()`, `check_win_devel()`,
`check_win_oldrelease()` (#1598).

Expand Down
31 changes: 19 additions & 12 deletions R/test.r
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#' Execute all \pkg{test_that} tests in a package.
#'
#' Tests are assumed to be located in either the \code{inst/tests/} or
#' \code{tests/testthat} directory (the latter is recommended).
#' See \code{\link[testthat]{test_dir}} for the naming convention of test
#' scripts within one of those directories and
#' \code{\link[testthat]{test_check}} for the folder structure conventions.
#'
#' If no testing infrastructure is present
#' (detected by the \code{uses_testthat} function), you'll be asked if you want
#' devtools to create it for you (in interactive sessions only). See
#' \code{\link{use_test}} for more details.
#' `test()` is a shortcut for [testthat::test_dir()].
#' `test_coverage()` is a shortcut for [covr::package_coverage()].
#'
#' @md
#' @param pkg package description, can be path or package name. See
#' \code{\link{as.package}} for more information
#' @param ... additional arguments passed to \code{\link[testthat]{test_dir}}
#' [as.package()] for more information
#' @param ... additional arguments passed to [testthat::test_dir()] and
#' [covr::package_coverage()]
#' @inheritParams testthat::test_dir
#' @inheritParams run_examples
#' @export
Expand Down Expand Up @@ -68,6 +62,19 @@ test <- function(pkg = ".", filter = NULL, ...) {
do.call(testthat::test_dir, testthat_args))
}

#' @export
#' @rdname test
test_coverage <- function(pkg = ".", ...) {
pkg <- as.package(pkg)

check_suggested("covr")

coverage <- covr::package_coverage(pkg$path, ...)
covr::report(coverage)

invisible(coverage)
}

find_test_dir <- function(path) {
testthat <- file.path(path, "tests", "testthat")
if (dir.exists(testthat)) return(testthat)
Expand Down
21 changes: 8 additions & 13 deletions man/test.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d99183

Please sign in to comment.