| 1 |
expect_no_output <- function(...) { |
| 2 |
testthat::expect_output(..., regexp = NA) |
| 3 |
} |
| 4 |
|
| 5 |
expect_safe_and_unsafe_unwinding <- function(state, |
| 6 |
with_unsafe, |
| 7 |
with_safe) { |
| 8 |
early_exit <- function(expr) { |
| 9 |
tryCatch(expr, my_cnd = identity) |
| 10 |
} |
| 11 |
|
| 12 |
with_unsafe(list("var" = "foo"), NULL) |
| 13 |
expect_null(state[["var"]]) |
| 14 |
|
| 15 |
with_safe(list("var" = "foo"), NULL) |
| 16 |
expect_null(state[["var"]]) |
| 17 |
|
| 18 |
early_exit(with_safe(list("var" = "foo"), NULL)) |
| 19 |
expect_null(state[["var"]]) |
| 20 |
|
| 21 |
# Problematic behaviour with unsafe variant |
| 22 |
early_exit(with_unsafe(list("var" = "foo"), NULL)) |
| 23 |
expect_equal(state[["var"]], "foo") |
| 24 |
} |
| 25 |
|
| 26 |
en_locale_or_skip <- function() { |
| 27 |
tryCatch( |
| 28 |
error = function(...) skip("Can't set locale"), |
| 29 |
warning = function(...) skip("Can't set locale"), |
| 30 |
with_collate("en_US.UTF-8", NULL) |
| 31 |
) |
| 32 |
"en_US.UTF-8" |
| 33 |
} |
| 34 |
|
| 35 |
skip_if_cannot_knit <- function() { |
| 36 |
skip_if_not_installed("knitr") |
| 37 |
skip_if_not_installed("rmarkdown") |
| 38 |
skip_if(!rmarkdown::pandoc_available()) |
| 39 |
} |
| 40 |
|
| 41 |
# Used to skip tests that will fail when locale is set to C, for |
| 42 |
# instance `with_language()` tests. These tests should only be run |
| 43 |
# when using a locale like `en_US`. |
| 44 |
skip_if_c_locale <- function() { |
| 45 |
lc_all <- Sys.getenv("LC_ALL", "") |
| 46 |
skip_if(lc_all %in% c("C", "C.UTF-8")) |
| 47 |
|
| 48 |
if (lc_all == "") { |
| 49 |
lang <- Sys.getenv("LANG", "") |
| 50 |
skip_if(lang %in% c("C", "C.UTF-8")) |
| 51 |
} |
| 52 |
} |