Skip to content

Commit 057c2b2

Browse files
minor fixes for devtools::check
1 parent 1fa5c79 commit 057c2b2

File tree

6 files changed

+52
-72
lines changed

6 files changed

+52
-72
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export(use_tester)
2323
export(use_testignore)
2424
import(assertthat)
2525
importFrom(magrittr,"%>%")
26+
importFrom(stats,setNames)

R/testthis-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#' @name testthis
1212
#' @import assertthat
1313
#' @importFrom magrittr %>%
14+
#' @importFrom stats setNames
1415
#'
1516
#' @section Setting the project path:
1617
#'
Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
1-
context("get_test_coverage")
1+
context("Test_coverage")
22

3-
proj <- usethis::proj_get()
43

5-
test_that("test_Test_coverage works as expected", {
6-
tpkg <- rprojroot::find_testthat_root_file("testdata", "test_pkg")
7-
usethis::proj_set(tpkg)
8-
expect_error(dat <- get_test_coverage(), "Functions can only be detected for installed packages")
9-
usethis::proj_set(proj)
10-
expect_silent(dat <- get_test_coverage())
4+
test_that("get_pkg_tested_functions_from_desc", {
5+
6+
list_test_files_mock <- function(...) {
7+
paste0("/blah/blubb/tests/testthat/", c("test_foo", "test_bar"))
8+
}
9+
10+
extract_test_that_desc_mock <- function(...){
11+
list(
12+
c("foofun1", "testing foofun2"),
13+
c("barfun1", "barfun2", "foofun1")
14+
) %>%
15+
setNames(list_test_files_mock())
16+
}
17+
18+
get_pkg_functions_mock <- function(...){
19+
c("foofun1", "foofun2", "barfun1", "barfun2")
20+
}
21+
22+
23+
tres <- with_mock(
24+
get_pkg_tested_functions_from_desc(),
25+
list_test_files = list_test_files_mock,
26+
extract_test_that_desc = extract_test_that_desc_mock,
27+
get_pkg_functions = get_pkg_functions_mock
28+
)
29+
30+
31+
expect_identical(
32+
tres,
33+
list(
34+
foofun1 =
35+
c("/blah/blubb/tests/testthat/test_foo", "/blah/blubb/tests/testthat/test_bar"),
36+
foofun2 = "/blah/blubb/tests/testthat/test_foo",
37+
barfun1 = "/blah/blubb/tests/testthat/test_bar",
38+
barfun2 = "/blah/blubb/tests/testthat/test_bar")
39+
)
1140
})
1241

13-
usethis::proj_set(proj)
42+
43+
44+
45+
test_that("get_test_coverage works", {
46+
expect_silent(get_test_coverage())
47+
expect_silent(get_test_coverage(from_tags = FALSE))
48+
expect_silent(get_test_coverage(from_desc = FALSE))
49+
})

tests/testthat/test_Taglist.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test_that("extracting testthis tags works as expected", {
5656

5757
expect_identical(tdat$skip, TRUE)
5858
expect_identical(tdat$testfile, c("testthis_tags", "testthis_tags2"))
59-
expect_identical(
59+
expect_setequal(
6060
tdat$testing,
6161
c("%foofun%", "detect_testthis_comments", "extract_testthis_comments",
6262
"get_taglist", "testthis_tokenizer")
@@ -74,7 +74,7 @@ test_that("get_tag works as expected", {
7474
expect_identical(get_tag(tlist, 'testfile'),
7575
c('testthis_tags', 'testthis_tags2'))
7676

77-
expect_identical(
77+
expect_setequal(
7878
get_tag(tlist, 'testing'),
7979
c("%foofun%", "detect_testthis_comments", "extract_testthis_comments",
8080
"get_taglist", "testthis_tokenizer")

tests/testthat/test_Test_coverage.R

Lines changed: 0 additions & 57 deletions
This file was deleted.

vignettes/testthis.Rmd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ knitr::opts_chunk$set(
1616
fig.path = "README-"
1717
)
1818
19-
devtools::load_all('.')
2019
library(testthis)
2120
library(rstudioapi)
2221
```
@@ -167,10 +166,10 @@ test_that("parse_testthis_comments works as expected", {
167166
}
168167
```
169168

170-
The test_coverage summary for a package may look like this (+ marks function for
171-
which tests exist):
172169

173-
```{r}
170+
To display the test coverage use:
171+
172+
```{r, eval = FALSE}
174173
get_test_coverage()
175174
```
176175

0 commit comments

Comments
 (0)