Skip to content

Commit 9d4b844

Browse files
committed
test_this now behaves like lest_this, lest_this has been deprecated.
testers save source files and reaload package now before running
1 parent 8623c90 commit 9d4b844

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: testthis
22
Type: Package
33
Title: Utils and 'RStudio' Addins to Make Testing Even More Fun
4-
Version: 1.0.2.9000
4+
Version: 1.0.3
55
Authors@R: person("Stefan", "Fleck", email = "[email protected]", role = c("aut", "cre"))
66
Maintainer: Stefan Fleck <[email protected]>
77
Description:

NEWS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
# testthis 1.0.2.9000
1+
# testthis 1.0.3
22
* Maintenance Release to make vignette comply with new CRAN guidelines
3+
* test (`test_this()`, `test_subdir()`, etc..) functions now save all files in
4+
Rstudio and reload the package before running tests.
5+
* `lest_this()` has been Deprecated. `test_this()` now behaves like
6+
`lest_this()`
7+
38

49
# testthis 1.0.2
510

R/test_subdir.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
#'
4545
#' @export
4646
test_subdir <- function(subdir, ...){
47+
if (requireNamespace("rstudioapi", quietly = TRUE)){
48+
rstudioapi::documentSaveAll()
49+
}
50+
51+
devtools::load_all(usethis::proj_get())
52+
4753
testthat::test_dir(file.path(
4854
usethis::proj_get(), testthat::test_path(), subdir
4955
))
@@ -93,6 +99,12 @@ test_manual <- function(...){
9399
test_all <- function(
94100
...
95101
){
102+
if (requireNamespace("rstudioapi", quietly = TRUE)){
103+
rstudioapi::documentSaveAll()
104+
}
105+
106+
devtools::load_all(usethis::proj_get())
107+
96108
pkg_dir <- usethis::proj_get()
97109

98110
dirs <- basename(

R/test_this.R

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#' Test this file
22
#'
3-
#' This is a convenience function to run testthat tests in a single .R file. If
4-
#' the file currently open in the RStudio editor is called \code{my_function.R},
5-
#' \code{test_this()} calls \code{testthat::test_file()} on
6-
#' "tests/testthat/test_my_function.R". If the filename of the currently open
7-
#' file with starts with \code{test_} it will call \code{testthat::test_file()}
8-
#' on the current file.
3+
#' Runs testthat tests in a single .R file. If the file currently open in the
4+
#' RStudio editor is called `my_function.R`, `test_this()` calls
5+
#' `testthat::test_file()` on \file{tests/testthat/test_my_function.R}. If
6+
#' the filename of the currently open file with starts with `test_` it will
7+
#' call `testthat::test_file()` on the current file.
98
#'
109
#' This is useful in cases where you don't want to run all tests in a package
11-
#' via \code{devtools::test()} (CTRL+SHIFT+T).
10+
#' via `devtools::test()` (CTRL+SHIFT+T).
1211
#'
1312
#' @param ... passed on to [testthat::test_file()]
1413
#'
@@ -19,6 +18,12 @@
1918
test_this <- function(...){
2019
fname <- get_testfile_name()
2120

21+
if (requireNamespace("rstudioapi", quietly = TRUE)){
22+
rstudioapi::documentSaveAll()
23+
}
24+
25+
devtools::load_all(usethis::proj_get())
26+
2227
if(file.exists(fname)){
2328
message("Running tests in ", fname)
2429
testthat::test_file(fname, ...)
@@ -32,11 +37,14 @@ test_this <- function(...){
3237

3338

3439

35-
#' \code{lest_this()} does the same, but calls \code{devtools::load_all()}
36-
#' first.
40+
#' \code{lest_this()} Deprecated. Please us `test_this()` instead.
3741
#' @export
3842
#' @rdname test_this.R
3943
lest_this <- function(...){
40-
devtools::load_all()
44+
.Deprecated(
45+
msg = paste(
46+
"'test_this()' now reloads package by default. 'lest_this()' is no",
47+
"longer required and will be dropped in future versions."
48+
))
4149
test_this(...)
4250
}

0 commit comments

Comments
 (0)