From 1b92b87a5974df0289be582d8819910f1811438a Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Tue, 24 Nov 2020 15:12:36 -0600 Subject: [PATCH] New function to skip check() but run test() (#347) This allows using here::here() in tests. --- tests/testthat/helper-skip_check_but_run_test.R | 6 ++++++ tests/testthat/test-utils.R | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/testthat/helper-skip_check_but_run_test.R diff --git a/tests/testthat/helper-skip_check_but_run_test.R b/tests/testthat/helper-skip_check_but_run_test.R new file mode 100644 index 00000000..a4db9235 --- /dev/null +++ b/tests/testthat/helper-skip_check_but_run_test.R @@ -0,0 +1,6 @@ +skip_check_but_run_test <- function() { + testthat::skip_if_not( + fs::file_exists(here::here(".pacta")), + "Source code is unavailable" + ) +} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 06eae07f..88bb93db 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -15,3 +15,14 @@ test_that("use_r_packages() puts listed packages on search() path", { expect_true(is_attached(package)) } }) + +test_that("helper skip_check_but_run_test() works as expected", { + # This test should not be skipped during devtools::test() + # This test should be skipped during devtools::check() + # If you remove `skip_check_but_run_test()`, devtools::check() should error + skip_check_but_run_test() + + # This file should be available only when the source code is accessible, i.e. + # not during R CMD check, when the code runs from the system installation + expect_true(fs::file_exists(here::here(".pacta"))) +})