Skip to content

Commit

Permalink
Cleaned up tests and added missing testthis tags and ignores for expo…
Browse files Browse the repository at this point in the history
…rted functions
  • Loading branch information
s-fleck committed Oct 26, 2017
1 parent c2ffaa0 commit 7608cc6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
2 changes: 2 additions & 0 deletions tests/testthat/_testignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ test_manual
test_subdir
test_this
test_with_skip
test_all
test_skeleton
31 changes: 24 additions & 7 deletions tests/testthat/integration_tests/test_infrastructure.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ test_that("use_tester works as expected", {


test_that("use_test_subdir works as expected", {
#* @testing use_test_subdir
#* @testing use_acceptance_tests
#* @testing use_integration_tests
#* @testing use_manual_tests

package_state <- list.files(".", recursive = TRUE)
tpkg <- rprojroot::find_testthat_root_file("testdata", "test_pkg")
usethis::proj_set(tpkg)
Expand All @@ -118,22 +123,34 @@ test_that("use_test_subdir works as expected", {
),
"Creating"
)

edir <- file.path(tpkg, "tests", "testthat", "footests")
efile <- file.path(tpkg, "R", "testthis-testers.R")

expect_true(dir.exists(edir))
expect_true(file.exists(efile))
expect_true(file.size(efile) > 10)

# cleanup
unlink(efile)
unlink(edir, recursive = TRUE)
expect_false(file.exists(efile))
expect_false(file.exists(edir))


# Check if preset subdir creators work
edir <- file.path(tpkg, "tests/testthat/integration_tests/")
expect_output(expect_true(use_integration_tests()), "Creating")
expect_true(file.exists(edir))
unlink(edir, recursive = TRUE)

edir <- file.path(tpkg, "tests/testthat/acceptance_tests/")
expect_output(expect_true(use_acceptance_tests()), "Creating")
expect_true(file.exists(file.path(tpkg, "tests/testthat/acceptance_tests/")))
unlink(edir, recursive = TRUE)

edir <- file.path(tpkg, "tests/testthat/manual_tests/")
expect_output(expect_true(use_manual_tests()), "Creating")
expect_true(file.exists(edir))
unlink(edir, recursive = TRUE)


# Check for unexpected changes to package
package_state_new <- list.files(".", recursive = TRUE)
expect_identical(package_state, package_state_new)
expect_identical(package_state, list.files(".", recursive = TRUE))
usethis::proj_set(proj)
})
41 changes: 36 additions & 5 deletions tests/testthat/integration_tests/test_use_testdata.R
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)

0 comments on commit 7608cc6

Please sign in to comment.