Skip to content

Commit 877df00

Browse files
doc
1 parent 712ed9b commit 877df00

35 files changed

+163
-152
lines changed

R/open_testfile.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#' Open associated test_file
1+
#' Open associated test file
22
#'
33
#' If the currently open file in the RStudio editor is called \file{myfun.R} this
44
#' opens \file{tests/testthat/test_myfun.R} in a new tab. This function can also
5-
#' be used to jump back and forth between an R script and the associated test
6-
#' file.
5+
#' be used to jump back and forth between a script and the associated test
6+
#' file. You can modify this behaviour by putting the comment
7+
#' `#* @testfile anotherfile` anywhere in \file{myfun.R}.
78
#'
89
#' @export
910
open_testfile <- function(){

R/test_coverage.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
#' Get Test Coverage of Package
1+
#' Test coverage of package
22
#'
3-
#' This extracts the test coverage of the target package (usually the package
4-
#' you are working on). Bear in mind that testthis uses a checklist-approach for
5-
#' this, and depends that you either put the function name in your
6-
#' `test_that()` calls, or used test_this tags. If you want automatic
7-
#' analysis of test coverage, you must look in other packages such as `covr`.
3+
#' This determines the test coverage of the target package based on the `desc`
4+
#' argument of `test_that()` calls. If you require a more comprehensive analysis
5+
#' of thest coverage, try the package **covr** instead.
86
#'
97
#' `test_coverage` looks in `.covrignore` for functions that should be ignored
108
#' for coverage analysis (see [usethis::use_covr_ignore()])
119
#'
12-
#' @param from_tags Logical scalar. Checks the files if your test directory for
10+
#' @param from_tags `logical` scalar. Checks the files if your test directory for
1311
#' testthis tags. Specifically, if you have the comment `#* @testing myfunction`
1412
#' in any of your test files, myfunction will be marked as tested.
15-
#' @param from_desc Logical scalar. Checks the `desc` argument
13+
#' @param from_desc `logical` scalar. Checks the `desc` argument
1614
#' `test_that(...)` of the tests in your test directory for functions
1715
#' names. E.g. if you have a testfile that contains
1816
#' `test_that("myfunction works", {...})`, myfunction will be marked as

R/test_index.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
#' Generates an index the `desc` arguments of all `test_that()` calls in the
44
#' `tests/testthat` directory of a package.
55
#'
6-
#' @param markers `logical` scalar. Display RStudio markers. If `FALSE`, the
7-
#' index is printed to the console instead.
6+
#' @param markers `logical` scalar. If `TRUE`, new markers are created in the
7+
#' RStudio markers pane. If `FALSE`, the index is printed to the console
8+
#' instead.
89
#'
910
#' @return A `test_index` `data.frame` (invisibly if `markers == TRUE`)
1011
#' @export

R/test_skeleton.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#' @section Side effects:
88
#' Creates an R script file in the file system.
99
#'
10-
#' @param fname Character scalar. Target R script file to open. If empty the file
10+
#' @param fname `character` scalar. Target R script file to open. If empty the file
1111
#' currently open in the editor will be used.
12-
#' @param open Logical scalar. Should the test file be opened after it is created?
13-
#' @param sep Character scalar. Separator between \file{test} and \file{fname}
12+
#' @param open `logical` scalar. Should the test file be opened after it is created?
13+
#' @param sep `character` scalar. Separator between \file{test} and \file{fname}
1414
#' when constructing the test file name. Should either be `"_"` or `"-"` for
1515
#' compatibility with testthat.
1616
#'

R/test_subdir.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
#' own test subdirs instead.
3636
#'
3737
#' @inheritParams devtools::test
38-
#' @param subdir subdir of `inst/tests/` or `tests/testthat` that contains the
39-
#' tests
38+
#' @param subdir `character` scalar. subdir of `inst/tests/` or `tests/testthat`
39+
#' that contains the tests
4040
#' @param ... passed on to `devtools::test()`
4141
#' @seealso [`use_test_subdir()`]
4242
#'
43-
#' @return A [testthat_results] object (invisibly)
43+
#' @return A [testthat::testthat_results] object (invisibly)
4444
#'
4545
#' @export
4646
test_subdir <- function(subdir, ...){

R/test_this.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' call `testthat::test_file()` on the current file.
88
#'
99
#' This is useful in cases where you don't want to run all tests in a package
10-
#' via `devtools::test()` (CTRL+SHIFT+T).
10+
#' via `devtools::test()` (CTRL+SHIFT+T in RStudio).
1111
#'
1212
#' @param ... passed on to [testthat::test_file()]
1313
#'

R/testthis-package.R

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#' testthis also provides utility function to manage tests in subdirectories of
77
#' the test/testthis directory.
88
#'
9-
#' For details please refer to `vignette("testthis")`
9+
#' For details please refer to the
10+
#' [README](https://s-fleck.github.io/testthis/index.html)
1011
#'
1112
#' @name testthis
1213
#' @import assertthat
@@ -53,7 +54,7 @@
5354
#'
5455
#' * `@testing <functionname>`: mark `functionname` as tested.
5556
#' Should usually go next the associated `test_that()` call. This is used by
56-
#' `get_test_coverage()`.
57+
#' `test_coverage()`.
5758
#'
5859
#'
5960
#' @seealso [usethis::edit_r_profile()]
@@ -84,8 +85,6 @@ if(getRversion() >= "2.15.1") utils::globalVariables(c("."))
8485
toset <- !(names(op.testthis) %in% names(op))
8586
if(any(toset)) options(op.testthis[toset])
8687

87-
88-
8988
if (requireNamespace("crayon", quietly = TRUE) && crayon::has_color()){
9089

9190
style_error <- crayon::make_style("#BB3333", colors = 256)
@@ -111,7 +110,5 @@ if(getRversion() >= "2.15.1") utils::globalVariables(c("."))
111110
assign("style_accent", style_accent, envir = parent.env(environment()))
112111
assign("col_nchar", col_nchar, envir = parent.env(environment()))
113112

114-
115-
116113
invisible()
117114
}

R/use_test_subdir.R

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
#'
99
#' @inheritSection test_subdir Test subdirectory presets
1010
#'
11-
#' @param path Character scalar. Will be processed with [base::make.names()] to
11+
#' @param path `character` scalar. Will be processed with [base::make.names()] to
1212
#' make a syntactically valid name.
13-
#' @param make_tester Logical or character scalar. Create an R script with a
13+
#' @param make_tester `logical` or `character` scalar. Create an R script with a
1414
#' test helper function. If `TRUE` an R script file will be placed into the
1515
#' \file{R/} directory of the current package, containing a function definition
1616
#' for running the tests in `path`. The file will be named
1717
#' \file{testthis-testers.R}, but you can specify your own name by
18-
#' passing a character scalar to make_tester. See [use_tester()] for details.
19-
#' @param ignore_tester Logical. Add \file{tester} file to \file{.Rbuildignore}?
18+
#' passing a character scalar to `make_tester()`. See [use_tester()] for details.
19+
#' @param ignore_tester `logical` scalar`. Add \file{tester} file to \file{.Rbuildignore}?
2020
#' @seealso [`test_subdir()`]
2121
#' @family infrastructure
2222
#'
@@ -40,9 +40,8 @@ use_test_subdir <- function(
4040
){
4141
# Preconditions
4242
assert_that(
43-
is.scalar(path) && is.character(path),
44-
is.scalar(make_tester),
45-
is.scalar(is.logical(make_tester) || is.character(make_tester))
43+
is_scalar_character(path),
44+
is_scalar_bool(make_tester) || is_scalar_character(make_tester)
4645
)
4746

4847
# Process arguments
@@ -73,10 +72,11 @@ use_test_subdir <- function(
7372
#' in a predefined directory. This function powers the `make_tester` option
7473
#' of [use_test_subdir()] and you will likely not need to run it manually.
7574
#'
76-
#' @param path Name of the subdirectory oft \file{tests/testthat/} for which
77-
#' to create a tester function.
78-
#' @param ignore Logical. Add `tester_path` to \file{.Rbuildignore}?
79-
#' @param tester_path \R script file in which to store the tester functions
75+
#' @param path `character` scalar. Name of the subdirectory of
76+
#' \file{tests/testthat/} for which to create a tester function.
77+
#' @param ignore `logical` scalar. Add `tester_path` to \file{.Rbuildignore}?
78+
#' @param tester_path `logical` scalar. Path to the \R script file in which to
79+
#' store the tester functions
8080
#'
8181
#' @return `TRUE` on success (invisibly).
8282
#' @export
@@ -87,6 +87,11 @@ use_tester <- function(
8787
ignore = TRUE,
8888
tester_path = file.path("R", "testthis-testers.R")
8989
){
90+
assert_that(
91+
is_scalar_bool(ignore),
92+
is_scalar_character(tester_path)
93+
)
94+
9095
fname <- file.path(usethis::proj_get(), tester_path)
9196
assert(
9297
dir.exists(dirname(fname)),

R/use_testdata.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#'
66
#' @param ... \R objects to save to the \file{testdata} dir. If empty,
77
#' an empty directory is created.
8-
#' @param subdir Character scalar. Subdirectory of \file{testdata} to save
8+
#' @param subdir `character` scalar. Subdirectory of \file{testdata} to save
99
#' to / read from.
1010
#' @inheritParams base::readRDS
1111
#' @template overwrite
@@ -33,8 +33,9 @@ use_testdata <- function(
3333
){
3434
# Preconditions
3535
assert_that(
36-
is.flag(overwrite),
37-
is.null(subdir) || (is.scalar(subdir) && is.character(subdir))
36+
is_scalar_bool(overwrite),
37+
is_scalar_bool(ignore),
38+
is.null(subdir) || is_scalar_character(subdir)
3839
)
3940

4041

README.Rmd

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ output: github_document
1111
<!-- badges: end -->
1212

1313
**testthis** makes unit testing in R more comfortable. It is designed to
14-
complement the packages **testthat**, **devtools** and **usethis**.
14+
complement the packages
15+
[testthat](https://github.com/r-lib/testthat),
16+
[devtools](https://github.com/r-lib/devtools) and
17+
[usethis](https://github.com/r-lib/usethis).
1518

1619

1720

1821
## Overview
1922

20-
testthis provides RStudio addins for common tasks. These can be called like
21-
normal R function, but it is also possible to assigned to hotkeys to them in
22-
RStudio (*Tools/Modify Keyboard Shortcuts*).
23+
testthis provides RStudio addins for working with files that contain tests.
24+
These can be called like normal R function, but it is also possible to
25+
assigned them to hotkeys RStudio (*Tools/Modify Keyboard Shortcuts*).
2326

2427
* `test_this()`: Reloads the package and runs tests associated with the
2528
currently open R script file.
@@ -37,7 +40,7 @@ testthis also provides functions for managing tests in subdirectories of
3740

3841
* `use_testdata()` places a single R object in the `tests/testhat/testdata`
3942
directory. It is analoguous to `usethis::use_data()`, except that it saves the
40-
Object in the `.rds` format, which is more appropriate for single R objects
43+
object in the `.rds` format, which is more appropriate for single R objects
4144
than `.rda` or `.Rdata` (see `?readRDS`).
4245
* `use_testdata_raw()` creates the directory `tests/testhat/testdata-raw`. Use
4346
this directory to put scripts that generate the data in
@@ -46,22 +49,23 @@ testthis also provides functions for managing tests in subdirectories of
4649
saved with `use_testdata()`.
4750
* `use_test_subdir()` and `test_subdir()` for putting/running tests in
4851
subdirectories of `tests/testhat/`. These tests will *not* be run on CRAN or
49-
by `devtools::test()`. This is useful for tests that require
50-
external ressources (web, databases) or take long to execute.
52+
by `devtools::test()`. This is useful for tests that take a long time to
53+
execute, or that require external ressources (web, databases) that may not
54+
always be availabe.
5155

5256
`test_acceptance()`, `test_manual()` and
5357
`test_integration()` are presets to run tests in the
5458
`integration_tests`, `acceptance_tests` and `manual_tests` subdirectories of
5559
`test/testthat`.
5660

5761

58-
Testthis also provuides some primtivie code analys tools
62+
Testthis also provides some simple code analysis tools
5963

6064
* `test_coverage()` lists all functions of package and shows whether they
61-
are mentioned in anny `test_that(` calls's desc argument; e.g. if you have
65+
are mentioned in any `test_that()` calls' desc argument; e.g. if you have
6266
a testfile containing `test_that("testing that function foo works", <...>)`,
63-
`foo()` will show up as tested. This can function as a simple todo list for
64-
testing, but does not replace a proper test coverage analyzer like
67+
`foo()` will show up marked as tested. This can be used as a simple todo list
68+
for testing, but does not replace a proper test coverage analyzer like
6569
[covr](https://github.com/r-lib/covr).
6670
* `test_index()` produces an index of all `test_that()` calls. Supports RStudio
6771
Markers when run interactively from within RStudio.

0 commit comments

Comments
 (0)