From 64ecbe83606daee950dc634cfcd698aa0b0d2b34 Mon Sep 17 00:00:00 2001 From: John Blischak Date: Fri, 27 Oct 2023 14:08:34 -0400 Subject: [PATCH 1/4] Make skip_if_offline() more robust by checking multiple hosts --- R/skip.R | 9 +++++++-- man/skip.Rd | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/R/skip.R b/R/skip.R index f602ca925..2db59df37 100644 --- a/R/skip.R +++ b/R/skip.R @@ -122,14 +122,19 @@ package_version <- function(x) { #' @export #' @rdname skip -skip_if_offline <- function(host = "r-project.org") { +skip_if_offline <- function(host = c("r-project.org", "github.com", "captive.apple.com")) { skip_on_cran() check_installed("curl") skip_if_not(has_internet(host), "offline") } has_internet <- function(host) { - !is.null(curl::nslookup(host, error = FALSE)) + for (h in host) { + if (!is.null(curl::nslookup(h, error = FALSE))) { + return(TRUE) + } + } + return(FALSE) } #' @export diff --git a/man/skip.Rd b/man/skip.Rd index 516e09b93..8459eadc5 100644 --- a/man/skip.Rd +++ b/man/skip.Rd @@ -22,7 +22,7 @@ skip_if(condition, message = NULL) skip_if_not_installed(pkg, minimum_version = NULL) -skip_if_offline(host = "r-project.org") +skip_if_offline(host = c("r-project.org", "github.com", "captive.apple.com")) skip_on_cran() From 267f023d2e6df9839018fc180776cb60eff5edd6 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 29 Nov 2023 08:48:31 -0600 Subject: [PATCH 2/4] Just use captive.apple.com --- R/skip.R | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/R/skip.R b/R/skip.R index 2db59df37..d0a1c7d97 100644 --- a/R/skip.R +++ b/R/skip.R @@ -122,19 +122,14 @@ package_version <- function(x) { #' @export #' @rdname skip -skip_if_offline <- function(host = c("r-project.org", "github.com", "captive.apple.com")) { +skip_if_offline <- function(host = "captive.apple.com") { skip_on_cran() check_installed("curl") skip_if_not(has_internet(host), "offline") } has_internet <- function(host) { - for (h in host) { - if (!is.null(curl::nslookup(h, error = FALSE))) { - return(TRUE) - } - } - return(FALSE) + !is.null(curl::nslookup(host, error = FALSE)) } #' @export From 428dfa0c993e3d2931c63de635500136da39bbd6 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 29 Nov 2023 08:50:31 -0600 Subject: [PATCH 3/4] Add news bullet --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 4befc71e9..051477b72 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # testthat (development version) +* `skip_if_offline()` now uses `captive.apple.com` by default. This is the + host that Apple devices use to check that they're online so should be + a higher reliability host than `r-project.org` (@jdblischak, #1890). + * `test_file(desc = )` will now find `describe()` tests as well as `testthat()` tests (#1903). From 80980945bb94f331d3e833ff28e905ff17266419 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 29 Nov 2023 08:50:54 -0600 Subject: [PATCH 4/4] Re-document --- man/skip.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/skip.Rd b/man/skip.Rd index 8459eadc5..fa1bf7c76 100644 --- a/man/skip.Rd +++ b/man/skip.Rd @@ -22,7 +22,7 @@ skip_if(condition, message = NULL) skip_if_not_installed(pkg, minimum_version = NULL) -skip_if_offline(host = c("r-project.org", "github.com", "captive.apple.com")) +skip_if_offline(host = "captive.apple.com") skip_on_cran()