Skip to content

Commit

Permalink
Revert change + add skip for Old Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Nov 27, 2024
1 parent ad8d8ac commit 11b1a60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 deletions R/write_testthat_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}
3 changes: 2 additions & 1 deletion tests/testthat/test-draft_validation.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
skip_on_cran()
work_path <- "./generated_r_files"

if (fs::dir_exists(path = work_path)) {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 11b1a60

Please sign in to comment.