Skip to content

Commit

Permalink
Rename test_file to test_active_file and the coverage equivalents
Browse files Browse the repository at this point in the history
These functions conflict with testthat::test_file

Fixes #2125
  • Loading branch information
jimhester committed Mar 30, 2021
1 parent ff45628 commit 7655af0
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 46 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Depends:
Imports:
callr (>= 3.6.0),
cli (>= 2.3.1),
covr (>= 3.5.1),
desc (>= 1.3.0),
ellipsis (>= 0.3.1),
fs (>= 1.5.0),
Expand All @@ -50,6 +49,7 @@ Imports:
withr (>= 2.4.1)
Suggests:
BiocManager (>= 1.30.12),
covr (>= 3.5.1),
curl (>= 4.3),
digest (>= 0.6.27),
DT (>= 0.17),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export(source_url)
export(spell_check)
export(submit_cran)
export(test)
export(test_active_file)
export(test_coverage)
export(test_coverage_active_file)
export(test_coverage_file)
export(test_file)
export(uninstall)
Expand Down
24 changes: 11 additions & 13 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
# devtools (development version)

* `test_file()` has been renamed to `test_active_file()` and `test_coverage_file()` has been renamed to `test_coverage_active_file()` to avoid a name collision with `testthat::test_file()`.
The previous names have been soft deprecated in this release, they will be hard deprecated in the next release and eventually removed. (#2125)

* `build_readme()` now supports readme files located in `inst/README.Rmd`, as intended (#2333)

* DT has been moved from Imports to Suggests. DT is only needed when running
`test_coverage()` so now you'll be prompted to install it when needed.
* The covr and DT packages have been moved from Imports to Suggests.
They are only needed when running `test_coverage()` and `test_coverage_active_file()` so now you'll be prompted to install them we needed.

* Make the `.gitignore` entries automatically created by `build_vignettes` more
specific. (@klmr, #2317)
* Make the `.gitignore` entries automatically created by `build_vignettes` more specific. (@klmr, #2317)

* Add a check to `change_maintainer_email()` to assess whether the email is actually changed.
If the email is not changed, the code now stops such that an email is not accidentally sent to the wrong recipient. (@emilsjoerup, #2073)

* `check()` only re-documents if you have a matching version of roxygen2
(#2263).
* `check()` only re-documents if you have a matching version of roxygen2 (#2263).
* `run_examples(fresh = TRUE)` again works without error (#2264)

* `pkgload::inst()` is no longer re-exported (#2218).

* Old `check_results()` function has been removed. It was not used by any
CRAN package, and much better alternatives are available in the
[rcmdcheck](http://github.com/r-lib/rcmdcheck) package.
* Old `check_results()` function has been removed.
It was not used by any CRAN package, and much better alternatives are available in the [rcmdcheck](http://github.com/r-lib/rcmdcheck) package.

* The internal `devtest()` function has been removed.

* Now uses (what will become) testthat 3.0.0 to power `test()`, `test_file()`,
`test_coverage()`, and `test_coverage_file()`. The major difference is that
`test_file()` now generates a compact summary that takes up less space on
the console.
* Now uses testthat 3.0.0 to power `test()`, `test_active_file()`, `test_coverage()`, and `test_coverage_active_file()`.
The major difference is that `test_active-file()` now generates a compact summary that takes up less space on the console.

* Switched to fs for all file system functions (#2331, @malcolmbarrett)

Expand Down
27 changes: 21 additions & 6 deletions R/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#' @description
#' * `test()` runs all tests in a package. It's a shortcut for
#' [testthat::test_dir()]
#' * `test_file()` runs `test()` on the active file.
#' * `test_active_file()` runs `test()` on the active file.
#' * `test_coverage()` computes test coverage for your package. It's a
#' shortcut for [covr::package_coverage()] plus [covr::report()].
#' * `test_coverage_file()` computes test coverage for the active file. It's a
#' * `test_coverage_active_file()` computes test coverage for the active file. It's a
#' shortcut for [covr::file_coverage()] plus [covr::report()].
#'
#' @template devtools
Expand Down Expand Up @@ -42,9 +42,16 @@ test <- function(pkg = ".", filter = NULL, stop_on_failure = FALSE, export_all =
)
}

#' @rdname devtools-deprecated
#' @export
#' @rdname test
test_file <- function(file = find_active_file(), ...) {
lifecycle::deprecate_soft("2.4.0", "test_file()", "test_active_file()")
test_active_file(file, ...)
}

#' @export
#' @rdname test
test_active_file <- function(file = find_active_file(), ...) {
save_all()
test_files <- find_test_file(file)
pkg <- as.package(path_dir(test_files)[[1]])
Expand All @@ -57,9 +64,8 @@ test_file <- function(file = find_active_file(), ...) {
#' @param show_report Show the test coverage report.
#' @export
#' @rdname test
# we now depend on DT in devtools so DT is installed when users call test_coverage
test_coverage <- function(pkg = ".", show_report = interactive(), ...) {
rlang::check_installed("DT")
rlang::check_installed(c("covr", "DT"))

save_all()
pkg <- as.package(pkg)
Expand All @@ -78,9 +84,18 @@ test_coverage <- function(pkg = ".", show_report = interactive(), ...) {
invisible(coverage)
}

#' @rdname devtools-deprecated
#' @export
test_coverage_file <- function(file = find_active_file(), ...) {
lifecycle::deprecate_soft("2.4.0", "test_coverage()", "test_coverage_active_file()")
test_coverage_active_file(file, ...)
}

#' @rdname test
#' @export
test_coverage_file <- function(file = find_active_file(), filter = TRUE, show_report = interactive(), export_all = TRUE, ...) {
test_coverage_active_file <- function(file = find_active_file(), filter = TRUE, show_report = interactive(), export_all = TRUE, ...) {
rlang::check_installed(c("covr", "DT"))

save_all()
test_files <- find_test_file(file)
pkg <- as.package(path_dir(file)[[1]])
Expand Down
13 changes: 5 additions & 8 deletions man/check.Rd

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

11 changes: 9 additions & 2 deletions man/devtools-deprecated.Rd

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

10 changes: 5 additions & 5 deletions man/load_all.Rd

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

12 changes: 6 additions & 6 deletions man/test.Rd

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

9 changes: 4 additions & 5 deletions tests/testthat/test-test.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
test_test <- function(...) {
suppressMessages(test(..., reporter = "silent"))
}
test_test_file <- function(...) {
# Avoid accidentally using testthat::test_file()
suppressMessages(devtools::test_file(..., reporter = "silent"))
test_test_active_file <- function(...) {
suppressMessages(test_active_file(..., reporter = "silent"))
}

test_that("Package can be tested with testthat not on search path", {
Expand All @@ -27,8 +26,8 @@ test_that("Filtering works with devtools::test", {
expect_equal(length(out), 1)
})

test_that("devtools::test_file works", {
out <- test_test_file(test_path("testTest/tests/testthat/test-dummy.R"))
test_that("devtools::test_active_file works", {
out <- test_test_active_file(test_path("testTest/tests/testthat/test-dummy.R"))
expect_equal(length(out), 1)
})

Expand Down

0 comments on commit 7655af0

Please sign in to comment.