diff --git a/R/utils.R b/R/utils.R index a4f624ce2..88e13c151 100644 --- a/R/utils.R +++ b/R/utils.R @@ -80,7 +80,9 @@ write_if_different <- function(path, contents, check = TRUE) { FALSE } else { cat(sprintf('Writing %s\n', name)) - writeLines(contents, path) + con <- file(path, encoding = "UTF-8") + on.exit(close(con), add = TRUE) + writeLines(contents, con) TRUE } } diff --git a/tests/testthat/test-nonASCII.R b/tests/testthat/test-nonASCII.R index f7af5d3b2..eeb24167d 100644 --- a/tests/testthat/test-nonASCII.R +++ b/tests/testthat/test-nonASCII.R @@ -8,6 +8,9 @@ test_that("can generate nonASCII document", { expect_true(file.exists(file.path(test_pkg, "man", "printChineseMsg.Rd"))) cnChar <- readLines(file.path(test_pkg, "man", "printChineseMsg.Rd"), encoding = "UTF-8") - expect_true(any(grepl("我爱中文", cnChar)) && any(grepl("中文注释", cnChar))) + # Because the parse in testthat::test don't specify encoding to UTF-8 as well, + # so we have to use unicode escapes. + expect_true(any(grepl("\u6211\u7231\u4e2d\u6587", cnChar))) + expect_true(any(grepl("\u4e2d\u6587\u6ce8\u91ca", cnChar))) })