Skip to content

Commit

Permalink
Set LANG in LANGUAGE tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Sep 26, 2023
1 parent a0d49ff commit 08619ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ skip_if_cannot_knit <- function() {
skip_if_not_installed("rmarkdown")
skip_if(!rmarkdown::pandoc_available())
}

# Need to also specify `LC_ALL` because `LANGUAGE` is ignored when
# `LANG` is set (here via `LC_ALL`) to `C` or `C.UTF-8`
with_lang <- function(lc, language, expr) {
withr::local_envvar(c(LC_ALL = lc))
withr::local_language(language)
expr
}
10 changes: 5 additions & 5 deletions tests/testthat/test-language.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
test_that("can temporarily change language", {
skip_if_not(has_nls())

expect_error(with_language("en", mean[[1]]), "not subsettable")
expect_error(with_language("fr", mean[[1]]), "non indi\u00e7able")
expect_error(with_language("es", mean[[1]]), "no es subconjunto")
expect_error(with_lang("en_GB", "en", mean[[1]]), "not subsettable")
expect_error(with_lang("fr_FR", "fr", mean[[1]]), "non indi\u00e7able")
expect_error(with_lang("es_ES", "es", mean[[1]]), "no es subconjunto")

# can use either _ or -
expect_error(with_language("pt_BR", mean[[1]]), "não possível dividir")
expect_error(with_language("pt-BR", mean[[1]]), "não possível dividir")
expect_error(with_lang("pt_BR", "pt_BR", mean[[1]]), "não possível dividir")
expect_error(with_lang("pt_BR", "pt-BR", mean[[1]]), "não possível dividir")
})

test_that("warns if LANG=C", {
Expand Down

0 comments on commit 08619ef

Please sign in to comment.