-
Notifications
You must be signed in to change notification settings - Fork 763
Description
devtools::test() report failures not reported with rcmdcheck(), the “Run Test” button in RSudio or e.g. testthat::test_dir(). Also, my package under test seems to work well.
I am testing a package with data in an environment. The initial (‘factory’)data is created when the package is build and it may be manipulated later by its users.
A minimal package producing the issue is shown below. It also contains two work-arounds:
1. Include “testEnvir <- testTest:::testEnvir” in setMenu()
But this would produce notes that the “::::” are rarely needed
2. Remove the ‘detach’ function in the test file.
But I want the guarantee to test always on the same data
My package, called testTest, contains only the following one R file:
testEnvir <- new.env()
testEnvir$menu <- "spam"
setMenu <- function (menu) {
# testEnvir <- testTest:::testEnvir
testEnvir$menu <- menu
}
And the following test file:
require (testthat)
test_that("-", { expect_true(TRUE) }) # used to enforce the RStudio top right "Run Test" button
if (isNamespaceLoaded ("testTest")) detach (package:testTest, unload = TRUE) # to get a fresh version
require (testTest)
testEnvir <- testTest:::testEnvir
test_that ("testTestTest", {
expect_equal (testEnvir$menu, "spam")
testEnvir$menu <- "eggs"
expect_equal (testEnvir$menu, "eggs")
setMenu ("bacon")
expect_equal (testEnvir$menu, "bacon") # fails with devtools::test() only
})