From bd057820211e0b6a9abb32213d59707b5e815c31 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 3 Jan 2022 18:46:41 -0600 Subject: [PATCH] Only use part of local_reproducible_output() in Reporter$local_user_output() Fixes #1285 --- NEWS.md | 3 +++ R/reporter.R | 4 +++- tests/testthat/test-reporter.R | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 39a2f476a..ba96c81e5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # testthat (development version) +* `test_that()` no longer inappropriately skips when calling `expect_equal()` + when you've temporarily set the locale to non-UTF-8 (#1285). + * `local_reproducible_output()` now sets the global option `cli.num_colors` in addition to `crayon.enabled`. diff --git a/R/reporter.R b/R/reporter.R index 66cbd7135..d59441442 100644 --- a/R/reporter.R +++ b/R/reporter.R @@ -66,9 +66,11 @@ Reporter <- R6::R6Class("Reporter", local_reproducible_output( width = self$width, crayon = self$crayon, - unicode = self$unicode, .env = .env ) + # Can't set unicode with local_reproducible_output() because it can + # generate a skip if you're temporarily using a non-UTF-8 locale + withr::local_options(cli.unicode = self$unicode, .local_envir = .env) }, cat_tight = function(...) { diff --git a/tests/testthat/test-reporter.R b/tests/testthat/test-reporter.R index 8863527ad..61bc7e52c 100644 --- a/tests/testthat/test-reporter.R +++ b/tests/testthat/test-reporter.R @@ -16,3 +16,8 @@ test_that("can control output with file arg/option", { ) expect_snapshot_output(read_lines(path)) }) + +test_that("should not automatically skip in non-utf-8 locales", { + withr::local_locale(LC_CTYPE = "C") + expect_true(TRUE) +})