test_test <- function(...) {
suppressMessages(test(..., reporter = "silent"))
}
test_that("Package can be tested with testthat not on search path", {
pkg1 <- test_path("testTest")
pkg2 <- test_path("testTestWithDepends")
testthat_pos <- which(search() == "package:testthat")
if (length(testthat_pos) > 0) {
testthat_env <- detach(pos = testthat_pos)
on.exit(attach(testthat_env, testthat_pos), add = TRUE)
}
test_test(pkg1)
expect_true(TRUE)
test_test(pkg2)
expect_true(TRUE)
})
test_that("Filtering works with devtools::test", {
out <- test_test(test_path("testTest"), filter = "dummy")
expect_equal(length(out), 1)
})
test_that("devtools::test_file works", {
expect_error(test_file("testTest/DESCRIPTION"), "are not valid R or src files")
suppressMessages(
test_file("testTest/tests/testthat/test-dummy.R", pkg = "testTest", reporter = "silent")
)
suppressMessages(
test_file("testTest/R/dummy.R", pkg = "testTest", reporter = "silent")
)
expect_true(TRUE)
})
test_that("TESTTHAT_PKG environment varaible is set", {
test_test(test_path("testTest"), filter = "envvar")
expect_true(TRUE)
})
test_that("stop_on_failure defaults to FALSE", {
expect_error(
test_test(test_path("testTestWithFailure")),
NA
)
expect_error(
test_test(test_path("testTestWithFailure"), stop_on_failure = TRUE),
"Test failures"
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.