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# '
1918test_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
3943lest_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