From 11b1a6025ecf7e141a7db2d90067d80d5b494c52 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 27 Nov 2024 16:09:06 -0500 Subject: [PATCH] Revert change + add skip for Old Windows --- R/write_testthat_file.R | 12 +++++++++--- tests/testthat/helper.R | 5 +++++ tests/testthat/test-draft_validation.R | 3 ++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/R/write_testthat_file.R b/R/write_testthat_file.R index a858698b2..ae37b0f94 100644 --- a/R/write_testthat_file.R +++ b/R/write_testthat_file.R @@ -681,13 +681,19 @@ pb_write_file <- function( on.exit(close(file_connection)) - # We use Unix to write testthat file - lines <- gsub("\r?\n", "\n", lines) + # Obtain the appropriate line ending based on the platform + if (.Platform$OS.type == "windows") { + line_ending <- "\r\n" + } else { + line_ending <- "\n" + } + + lines <- gsub("\r?\n", line_ending, lines) writeLines( text = enc2utf8(lines), con = file_connection, - sep = "\n", + sep = line_ending, useBytes = TRUE ) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index aa01efa8c..3d0fceee3 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -4,3 +4,8 @@ expect_equal_unlist <- function(object, expected, ...) { expected ) } + +skip_if_not_utf8 <- function() { + # likely on Windows for R < 4.2 + skip_if_not(l10n_info()$`UTF-8`) +} diff --git a/tests/testthat/test-draft_validation.R b/tests/testthat/test-draft_validation.R index 48bf0ec0b..e5e21d4ee 100644 --- a/tests/testthat/test-draft_validation.R +++ b/tests/testthat/test-draft_validation.R @@ -1,3 +1,4 @@ +skip_on_cran() work_path <- "./generated_r_files" if (fs::dir_exists(path = work_path)) { @@ -90,7 +91,7 @@ test_that("draft validations for data tables can be generated", { }) test_that("draft validations for data tables can be generated in different languages", { - + skip_if_not_utf8() write_draft_snapshot_test(dataset = pointblank::small_table, filename = "st_en", lang = "en") write_draft_snapshot_test(dataset = pointblank::small_table, filename = "st_fr", lang = "fr") write_draft_snapshot_test(dataset = pointblank::small_table, filename = "st_de", lang = "de")