Skip to content

Commit 7655af0

Browse files
committed
Rename test_file to test_active_file and the coverage equivalents
These functions conflict with testthat::test_file Fixes #2125
1 parent ff45628 commit 7655af0

9 files changed

Lines changed: 64 additions & 46 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Depends:
2727
Imports:
2828
callr (>= 3.6.0),
2929
cli (>= 2.3.1),
30-
covr (>= 3.5.1),
3130
desc (>= 1.3.0),
3231
ellipsis (>= 0.3.1),
3332
fs (>= 1.5.0),
@@ -50,6 +49,7 @@ Imports:
5049
withr (>= 2.4.1)
5150
Suggests:
5251
BiocManager (>= 1.30.12),
52+
covr (>= 3.5.1),
5353
curl (>= 4.3),
5454
digest (>= 0.6.27),
5555
DT (>= 0.17),

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export(source_url)
6868
export(spell_check)
6969
export(submit_cran)
7070
export(test)
71+
export(test_active_file)
7172
export(test_coverage)
73+
export(test_coverage_active_file)
7274
export(test_coverage_file)
7375
export(test_file)
7476
export(uninstall)

NEWS.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
# devtools (development version)
22

3+
* `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()`.
4+
The previous names have been soft deprecated in this release, they will be hard deprecated in the next release and eventually removed. (#2125)
5+
36
* `build_readme()` now supports readme files located in `inst/README.Rmd`, as intended (#2333)
47

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

8-
* Make the `.gitignore` entries automatically created by `build_vignettes` more
9-
specific. (@klmr, #2317)
11+
* Make the `.gitignore` entries automatically created by `build_vignettes` more specific. (@klmr, #2317)
1012

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

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

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

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

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

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

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

R/test.R

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#' @description
44
#' * `test()` runs all tests in a package. It's a shortcut for
55
#' [testthat::test_dir()]
6-
#' * `test_file()` runs `test()` on the active file.
6+
#' * `test_active_file()` runs `test()` on the active file.
77
#' * `test_coverage()` computes test coverage for your package. It's a
88
#' shortcut for [covr::package_coverage()] plus [covr::report()].
9-
#' * `test_coverage_file()` computes test coverage for the active file. It's a
9+
#' * `test_coverage_active_file()` computes test coverage for the active file. It's a
1010
#' shortcut for [covr::file_coverage()] plus [covr::report()].
1111
#'
1212
#' @template devtools
@@ -42,9 +42,16 @@ test <- function(pkg = ".", filter = NULL, stop_on_failure = FALSE, export_all =
4242
)
4343
}
4444

45+
#' @rdname devtools-deprecated
4546
#' @export
46-
#' @rdname test
4747
test_file <- function(file = find_active_file(), ...) {
48+
lifecycle::deprecate_soft("2.4.0", "test_file()", "test_active_file()")
49+
test_active_file(file, ...)
50+
}
51+
52+
#' @export
53+
#' @rdname test
54+
test_active_file <- function(file = find_active_file(), ...) {
4855
save_all()
4956
test_files <- find_test_file(file)
5057
pkg <- as.package(path_dir(test_files)[[1]])
@@ -57,9 +64,8 @@ test_file <- function(file = find_active_file(), ...) {
5764
#' @param show_report Show the test coverage report.
5865
#' @export
5966
#' @rdname test
60-
# we now depend on DT in devtools so DT is installed when users call test_coverage
6167
test_coverage <- function(pkg = ".", show_report = interactive(), ...) {
62-
rlang::check_installed("DT")
68+
rlang::check_installed(c("covr", "DT"))
6369

6470
save_all()
6571
pkg <- as.package(pkg)
@@ -78,9 +84,18 @@ test_coverage <- function(pkg = ".", show_report = interactive(), ...) {
7884
invisible(coverage)
7985
}
8086

87+
#' @rdname devtools-deprecated
88+
#' @export
89+
test_coverage_file <- function(file = find_active_file(), ...) {
90+
lifecycle::deprecate_soft("2.4.0", "test_coverage()", "test_coverage_active_file()")
91+
test_coverage_active_file(file, ...)
92+
}
93+
8194
#' @rdname test
8295
#' @export
83-
test_coverage_file <- function(file = find_active_file(), filter = TRUE, show_report = interactive(), export_all = TRUE, ...) {
96+
test_coverage_active_file <- function(file = find_active_file(), filter = TRUE, show_report = interactive(), export_all = TRUE, ...) {
97+
rlang::check_installed(c("covr", "DT"))
98+
8499
save_all()
85100
test_files <- find_test_file(file)
86101
pkg <- as.package(path_dir(file)[[1]])

man/check.Rd

Lines changed: 5 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/devtools-deprecated.Rd

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/load_all.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/test.Rd

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-test.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
test_test <- function(...) {
22
suppressMessages(test(..., reporter = "silent"))
33
}
4-
test_test_file <- function(...) {
5-
# Avoid accidentally using testthat::test_file()
6-
suppressMessages(devtools::test_file(..., reporter = "silent"))
4+
test_test_active_file <- function(...) {
5+
suppressMessages(test_active_file(..., reporter = "silent"))
76
}
87

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

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

0 commit comments

Comments
 (0)