-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up tests and added missing testthis tags and ignores for expo…
…rted functions
- Loading branch information
Showing
3 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ test_manual | |
test_subdir | ||
test_this | ||
test_with_skip | ||
test_all | ||
test_skeleton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
context("use_testdata") | ||
|
||
proj <- usethis::proj_get() | ||
|
||
|
||
test_that("saving and loading testdata works", { | ||
#* @testing read_testdata | ||
#* @testing use_testdata | ||
|
||
test_that("use_testdata works as expected", { | ||
package_state <- list.files(".", recursive = TRUE) | ||
tpkg <- file.path(rprojroot::find_testthat_root_file("testdata", "test_pkg")) | ||
usethis::proj_set(tpkg) | ||
efile <- file.path(tpkg, "tests", "testthat", "testdata", "iris.rds") | ||
|
||
expect_message(use_testdata(iris), "Saving to") | ||
expect_true(file.exists(rprojroot::find_testthat_root_file("testdata", "iris.rds"))) | ||
|
||
# Test saving and loading | ||
expect_message(use_testdata(iris), "Saving to") | ||
expect_true(file.exists(efile)) | ||
tdat <- read_testdata("iris.rds") | ||
expect_identical(iris, tdat) | ||
unlink(efile) | ||
|
||
# Check if tests did not modify package | ||
usethis::proj_set(proj) | ||
expect_identical(list.files(".", recursive = TRUE), package_state) | ||
}) | ||
|
||
unlink(rprojroot::find_testthat_root_file("testdata", "iris.rds")) | ||
expect_false(file.exists(rprojroot::find_testthat_root_file("testdata", "iris.rds"))) | ||
|
||
test_that("use_testdata_raw works", { | ||
#* @testing use_testdata_raw | ||
|
||
package_state <- list.files(".", recursive = TRUE) | ||
tpkg <- file.path(rprojroot::find_testthat_root_file("testdata", "test_pkg")) | ||
usethis::proj_set(tpkg) | ||
efile <- file.path(tpkg, "tests", "testthat", "testdata-raw") | ||
|
||
|
||
# Test saving and loading | ||
expect_output(use_testdata_raw(), "Creating") | ||
expect_true(dir.exists(efile)) | ||
unlink(efile, recursive = TRUE) | ||
|
||
# Check if tests did not modify package | ||
usethis::proj_set(proj) | ||
expect_identical(list.files(".", recursive = TRUE), package_state) | ||
}) | ||
|
||
|
||
usethis::proj_set(proj) |