Skip to content

Commit 95d1c10

Browse files
committed
Don't override user-specified NOT_CRAN env var
Continutation of #2112
1 parent 7eb22e8 commit 95d1c10

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

R/auto-test.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ auto_test_package <- function(
8383
test_path <- normalizePath(file.path(path, "tests", "testthat"))
8484

8585
# Start by loading all code and running all tests
86-
withr::local_envvar("NOT_CRAN" = "true")
86+
local_assume_not_on_cran()
8787
pkgload::load_all(path)
8888
test_dir(
8989
test_path,

R/local.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ local_test_directory <- function(path, package = NULL, .env = parent.frame()) {
190190
}
191191

192192
local_interactive_reporter <- function(.env = parent.frame()) {
193-
# Definitely not on CRAN
194-
withr::local_envvar(NOT_CRAN = "true", .local_envir = .env)
193+
local_assume_not_on_cran()
195194
withr::local_options(testthat_interactive = TRUE, .local_envir = .env)
196195

197196
# Use edition from working directory

R/skip.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ local_on_cran <- function(on_cran, frame = caller_env()) {
190190
withr::local_envvar(NOT_CRAN = tolower(!on_cran), .local_envir = frame)
191191
}
192192

193+
# Assert that we're not on CRAN, but don't override the user's setting
194+
local_assume_not_on_cran <- function(frame = caller_env()) {
195+
if (Sys.getenv("NOT_CRAN") != "") {
196+
return()
197+
}
198+
withr::local_envvar("NOT_CRAN" = "true", .local_envir = frame)
199+
}
200+
193201
#' @export
194202
#' @param os Character vector of one or more operating systems to skip on.
195203
#' Supported values are `"windows"`, `"mac"`, `"linux"`, `"solaris"`,

R/test-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ test_local <- function(
6868
package <- pkgload::pkg_name(path)
6969
test_path <- file.path(pkgload::pkg_path(path), "tests", "testthat")
7070

71-
withr::local_envvar(NOT_CRAN = "true")
71+
local_assume_not_on_cran()
7272
test_dir(
7373
test_path,
7474
package = package,

tests/testthat/test-skip.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ test_that("local_on_cran sets NOT_CRAN", {
8888
})
8989
})
9090

91+
test_that("local_assume_not_on_cran() sets NOT_CRAN if not already set", {
92+
withr::local_envvar(NOT_CRAN = NA)
93+
local({
94+
local_assume_not_on_cran()
95+
expect_equal(Sys.getenv("NOT_CRAN"), "true")
96+
})
97+
98+
withr::local_envvar(NOT_CRAN = "false")
99+
local({
100+
local_assume_not_on_cran()
101+
expect_equal(Sys.getenv("NOT_CRAN"), "false")
102+
})
103+
})
104+
91105
test_that("skip_on_ci() works as expected", {
92106
withr::local_envvar(CI = "false")
93107
expect_no_skip(skip_on_ci())

0 commit comments

Comments
 (0)