Skip to content

Commit

Permalink
Set package in test_active_file()
Browse files Browse the repository at this point in the history
And update tests so they actually fail if not set correctly

Fixes #2470
  • Loading branch information
hadley committed Sep 20, 2022
1 parent c9696a6 commit 64d33bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion R/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ test_active_file <- function(file = find_active_file(), ...) {
if (is_rstudio_running()) {
rstudioapi::executeCommand("activateConsole", quiet = TRUE)
}
testthat::test_file(test_files, ..., load_package = "source")
testthat::test_file(
test_files,
package = pkg$package,
...,
load_package = "source"
)
}

#' @param show_report Show the test coverage report.
Expand Down
15 changes: 13 additions & 2 deletions tests/testthat/test-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,19 @@ test_that("devtools::test_active_file works", {
expect_equal(length(out), 1)
})

test_that("TESTTHAT_PKG environment varaible is set", {
test_test(test_path("testTest"), filter = "envvar")
test_that("TESTTHAT_PKG environment variable is set", {
withr::local_envvar("TESTTHAT_PKG" = "incorrect")

test_test(
test_path("testTest"),
filter = "envvar",
stop_on_failure = TRUE
)
test_active_file(
test_path("testTest/tests/testthat/test-envvar.R"),
stop_on_failure = TRUE
)

expect_true(TRUE)
})

Expand Down

0 comments on commit 64d33bc

Please sign in to comment.