From 41442ac3e18fda164026a71a73e651ad36e179a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Mon, 28 Oct 2024 15:55:51 +0100 Subject: [PATCH] Align with `withr::local_language()` from dev withr (#1879) Co-authored-by: Lionel Henry --- DESCRIPTION | 4 ++-- NEWS.md | 4 ++++ R/local.R | 7 ++----- man/local_test_context.Rd | 2 +- tests/testthat/test-local.R | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e8e7b9307..6ecca9c0f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,7 @@ Imports: rlang (>= 1.1.1), utils, waldo (>= 0.5.1), - withr (>= 2.5.0) + withr (>= 3.0.2) Suggests: covr, curl (>= 0.9.5), @@ -55,4 +55,4 @@ Config/testthat/parallel: true Config/testthat/start-first: watcher, parallel* Encoding: UTF-8 Roxygen: list(markdown = TRUE, r6 = FALSE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 diff --git a/NEWS.md b/NEWS.md index 6eb90a984..164a3df9c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # testthat (development version) +* `LANGUAGE` is now set to `"C"` in reprocucible environments (i.e. + `test_that()` blocks) to disable translations. This fixes warnings + about being unable to set the language to `"en"` (#1925). + # testthat 3.2.1 * Fix incorrect format string detected by latest R-devel. Fix thanks to diff --git a/R/local.R b/R/local.R index c327503ed..b8693bab0 100644 --- a/R/local.R +++ b/R/local.R @@ -98,7 +98,7 @@ local_reproducible_output <- function(width = 80, unicode = FALSE, rstudio = FALSE, hyperlinks = FALSE, - lang = "en", + lang = "C", .env = parent.frame()) { if (unicode) { @@ -133,10 +133,7 @@ local_reproducible_output <- function(width = 80, .local_envir = .env ) - if (isTRUE(capabilities("NLS")) && Sys.getenv("LANG") != "C") { - withr::local_language(lang, .local_envir = .env) - } - + withr::local_language(lang, .local_envir = .env) withr::local_collate("C", .local_envir = .env) } diff --git a/man/local_test_context.Rd b/man/local_test_context.Rd index af9ae02a5..91f53ff4e 100644 --- a/man/local_test_context.Rd +++ b/man/local_test_context.Rd @@ -13,7 +13,7 @@ local_reproducible_output( unicode = FALSE, rstudio = FALSE, hyperlinks = FALSE, - lang = "en", + lang = "C", .env = parent.frame() ) } diff --git a/tests/testthat/test-local.R b/tests/testthat/test-local.R index 0440340c5..8c0b4a3a4 100644 --- a/tests/testthat/test-local.R +++ b/tests/testthat/test-local.R @@ -21,7 +21,7 @@ test_that("local context is 'as promised' inside test_that()", { expect_equal(getOption("max.print"), 99999) expect_equal(Sys.getenv("RSTUDIO"), "") - expect_equal(Sys.getenv("LANGUAGE"), "en") + expect_equal(Sys.getenv("LANGUAGE"), "C") expect_equal(Sys.getlocale("LC_COLLATE"), "C") })