diff --git a/NEWS.md b/NEWS.md index 3928ecef6..be831873c 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). + * When a snapshot changes the hint also mentions that you can use `snapshot_review()` (#1500, @DanChaltiel). 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 c6c4c724f..0e75fb57d 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(readLines(path)) }) + +test_that("should not automatically skip in non-utf-8 locales", { + withr::local_locale(LC_CTYPE = "C") + expect_true(TRUE) +})