Skip to content

Commit 7608cc6

Browse files
committed
Cleaned up tests and added missing testthis tags and ignores for exported functions
1 parent c2ffaa0 commit 7608cc6

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

tests/testthat/_testignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ test_manual
77
test_subdir
88
test_this
99
test_with_skip
10+
test_all
11+
test_skeleton

tests/testthat/integration_tests/test_infrastructure.R

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ test_that("use_tester works as expected", {
106106

107107

108108
test_that("use_test_subdir works as expected", {
109+
#* @testing use_test_subdir
110+
#* @testing use_acceptance_tests
111+
#* @testing use_integration_tests
112+
#* @testing use_manual_tests
113+
109114
package_state <- list.files(".", recursive = TRUE)
110115
tpkg <- rprojroot::find_testthat_root_file("testdata", "test_pkg")
111116
usethis::proj_set(tpkg)
@@ -118,22 +123,34 @@ test_that("use_test_subdir works as expected", {
118123
),
119124
"Creating"
120125
)
121-
122126
edir <- file.path(tpkg, "tests", "testthat", "footests")
123127
efile <- file.path(tpkg, "R", "testthis-testers.R")
124128

125129
expect_true(dir.exists(edir))
126130
expect_true(file.exists(efile))
127131
expect_true(file.size(efile) > 10)
128-
129-
# cleanup
130132
unlink(efile)
131133
unlink(edir, recursive = TRUE)
132-
expect_false(file.exists(efile))
133-
expect_false(file.exists(edir))
134+
135+
136+
# Check if preset subdir creators work
137+
edir <- file.path(tpkg, "tests/testthat/integration_tests/")
138+
expect_output(expect_true(use_integration_tests()), "Creating")
139+
expect_true(file.exists(edir))
140+
unlink(edir, recursive = TRUE)
141+
142+
edir <- file.path(tpkg, "tests/testthat/acceptance_tests/")
143+
expect_output(expect_true(use_acceptance_tests()), "Creating")
144+
expect_true(file.exists(file.path(tpkg, "tests/testthat/acceptance_tests/")))
145+
unlink(edir, recursive = TRUE)
146+
147+
edir <- file.path(tpkg, "tests/testthat/manual_tests/")
148+
expect_output(expect_true(use_manual_tests()), "Creating")
149+
expect_true(file.exists(edir))
150+
unlink(edir, recursive = TRUE)
151+
134152

135153
# Check for unexpected changes to package
136-
package_state_new <- list.files(".", recursive = TRUE)
137-
expect_identical(package_state, package_state_new)
154+
expect_identical(package_state, list.files(".", recursive = TRUE))
138155
usethis::proj_set(proj)
139156
})
Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,49 @@
11
context("use_testdata")
22

3+
proj <- usethis::proj_get()
4+
5+
6+
test_that("saving and loading testdata works", {
7+
#* @testing read_testdata
8+
#* @testing use_testdata
39

4-
test_that("use_testdata works as expected", {
510
package_state <- list.files(".", recursive = TRUE)
11+
tpkg <- file.path(rprojroot::find_testthat_root_file("testdata", "test_pkg"))
12+
usethis::proj_set(tpkg)
13+
efile <- file.path(tpkg, "tests", "testthat", "testdata", "iris.rds")
614

7-
expect_message(use_testdata(iris), "Saving to")
8-
expect_true(file.exists(rprojroot::find_testthat_root_file("testdata", "iris.rds")))
915

16+
# Test saving and loading
17+
expect_message(use_testdata(iris), "Saving to")
18+
expect_true(file.exists(efile))
1019
tdat <- read_testdata("iris.rds")
1120
expect_identical(iris, tdat)
21+
unlink(efile)
22+
23+
# Check if tests did not modify package
24+
usethis::proj_set(proj)
25+
expect_identical(list.files(".", recursive = TRUE), package_state)
26+
})
1227

13-
unlink(rprojroot::find_testthat_root_file("testdata", "iris.rds"))
14-
expect_false(file.exists(rprojroot::find_testthat_root_file("testdata", "iris.rds")))
28+
29+
test_that("use_testdata_raw works", {
30+
#* @testing use_testdata_raw
31+
32+
package_state <- list.files(".", recursive = TRUE)
33+
tpkg <- file.path(rprojroot::find_testthat_root_file("testdata", "test_pkg"))
34+
usethis::proj_set(tpkg)
35+
efile <- file.path(tpkg, "tests", "testthat", "testdata-raw")
36+
37+
38+
# Test saving and loading
39+
expect_output(use_testdata_raw(), "Creating")
40+
expect_true(dir.exists(efile))
41+
unlink(efile, recursive = TRUE)
1542

1643
# Check if tests did not modify package
44+
usethis::proj_set(proj)
1745
expect_identical(list.files(".", recursive = TRUE), package_state)
1846
})
47+
48+
49+
usethis::proj_set(proj)

0 commit comments

Comments
 (0)