Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/auto-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ auto_test_package <- function(
test_path <- normalizePath(file.path(path, "tests", "testthat"))

# Start by loading all code and running all tests
withr::local_envvar("NOT_CRAN" = "true")
local_assume_not_on_cran()
pkgload::load_all(path)
test_dir(
test_path,
Expand Down
3 changes: 1 addition & 2 deletions R/local.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ local_test_directory <- function(path, package = NULL, .env = parent.frame()) {
}

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

# Use edition from working directory
Expand Down
8 changes: 8 additions & 0 deletions R/skip.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ local_on_cran <- function(on_cran, frame = caller_env()) {
withr::local_envvar(NOT_CRAN = tolower(!on_cran), .local_envir = frame)
}

# Assert that we're not on CRAN, but don't override the user's setting
local_assume_not_on_cran <- function(frame = caller_env()) {
if (Sys.getenv("NOT_CRAN") != "") {
return()
}
withr::local_envvar("NOT_CRAN" = "true", .local_envir = frame)
}

#' @export
#' @param os Character vector of one or more operating systems to skip on.
#' Supported values are `"windows"`, `"mac"`, `"linux"`, `"solaris"`,
Expand Down
2 changes: 1 addition & 1 deletion R/test-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test_local <- function(
package <- pkgload::pkg_name(path)
test_path <- file.path(pkgload::pkg_path(path), "tests", "testthat")

withr::local_envvar(NOT_CRAN = "true")
local_assume_not_on_cran()
test_dir(
test_path,
package = package,
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-skip.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ test_that("local_on_cran sets NOT_CRAN", {
})
})

test_that("local_assume_not_on_cran() sets NOT_CRAN if not already set", {
withr::local_envvar(NOT_CRAN = NA)
local({
local_assume_not_on_cran()
expect_equal(Sys.getenv("NOT_CRAN"), "true")
})

withr::local_envvar(NOT_CRAN = "false")
local({
local_assume_not_on_cran()
expect_equal(Sys.getenv("NOT_CRAN"), "false")
})
})

test_that("skip_on_ci() works as expected", {
withr::local_envvar(CI = "false")
expect_no_skip(skip_on_ci())
Expand Down
Loading