Skip to content

Commit

Permalink
Set the TESTTHAT_PKG environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester committed Nov 23, 2018
1 parent 55f982c commit cce501a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# devtools 2.0.1.9000 - Development

* `test()`, `test_coverage()` and `test_coverage_file()` now set the
`TESTTHAT_PKG` environment variable, so it is more consistent with running
the tests during `R CMD check` (testthat#787).

* `check()` now replaces existing environment variables rather than appending
them (#1914).

Expand Down
12 changes: 9 additions & 3 deletions R/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ test <- function(pkg = ".", filter = NULL, ...) {
withr::with_options(
c(useFancyQuotes = FALSE),
withr::with_envvar(
r_env_vars(),
c(r_env_vars(),
"TESTTHAT_PKG" = pkg$package
),
do.call(testthat::test_dir, testthat_args)
)
)
Expand All @@ -88,7 +90,9 @@ test_coverage <- function(pkg = ".", show_report = interactive(), ...) {
save_all()

withr::with_envvar(
r_env_vars(),
c(r_env_vars(),
"TESTTHAT_PKG" = pkg$package
),
coverage <- covr::package_coverage(pkg$path, ...)
)

Expand Down Expand Up @@ -224,7 +228,9 @@ test_coverage_file <- function(file = find_active_file(), filter = TRUE, show_re
env <- load_all(pkg$path, quiet = TRUE)$env

withr::with_envvar(
r_env_vars(),
c(r_env_vars(),
"TESTTHAT_PKG" = pkg$package
),
withr::with_dir("tests/testthat", {
coverage <- covr::environment_coverage(env, test_files, ...)
})
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ test_that("devtools::test_file works", {
test_file("testTest/R/dummy.R", pkg = "testTest", reporter = "stop")
expect_true(TRUE)
})

test_that("TESTTHAT_PKG environment varaible is set", {
expect_equal(Sys.getenv("TESTTHAT_PKG"), "devtools")
})

0 comments on commit cce501a

Please sign in to comment.