From 7608cc6352ad2ada05ddc64e58e9959df28a47f0 Mon Sep 17 00:00:00 2001 From: Stefan Fleck Date: Thu, 26 Oct 2017 23:34:21 +0200 Subject: [PATCH] Cleaned up tests and added missing testthis tags and ignores for exported functions --- tests/testthat/_testignore | 2 + .../integration_tests/test_infrastructure.R | 31 ++++++++++---- .../integration_tests/test_use_testdata.R | 41 ++++++++++++++++--- 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/tests/testthat/_testignore b/tests/testthat/_testignore index fca753b..9129e2b 100644 --- a/tests/testthat/_testignore +++ b/tests/testthat/_testignore @@ -7,3 +7,5 @@ test_manual test_subdir test_this test_with_skip +test_all +test_skeleton diff --git a/tests/testthat/integration_tests/test_infrastructure.R b/tests/testthat/integration_tests/test_infrastructure.R index 34dbd0f..bb89df8 100644 --- a/tests/testthat/integration_tests/test_infrastructure.R +++ b/tests/testthat/integration_tests/test_infrastructure.R @@ -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) @@ -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) }) diff --git a/tests/testthat/integration_tests/test_use_testdata.R b/tests/testthat/integration_tests/test_use_testdata.R index b75698f..2f9e4a3 100644 --- a/tests/testthat/integration_tests/test_use_testdata.R +++ b/tests/testthat/integration_tests/test_use_testdata.R @@ -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)