Skip to content

Commit ca30752

Browse files
tests: avoid invalid UTF-8 warning (#7209)
* tests: avoid invalid UTF-8 warning Under options(encoding="UTF-8"), writeLines() always tries to perform text conversion. Giving it bytes that aren't valid in the current encoding results in warnings. Avoid the warning by explicitly opening a file connection with encoding="" (no conversion). * local()ize the test, link to the PR Co-authored-by: Michael Chirico <[email protected]>
1 parent 294f7f2 commit ca30752

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

inst/tests/tests.Rraw

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21554,10 +21554,18 @@ test(2332.81, {M1[]=frev(M1); M1}, {M2[]=rev(M2); M2})
2155421554
test(2333, as.expression(data.table(a = 1))[["a"]], 1)
2155521555

2155621556
# regression test for hexdigits subscript overrun (uint8_t wraps over 255, unsigned overflow is well defined in c)
21557-
f = tempfile()
21558-
writeLines(c('a', rep('0x1.ffffp0', 10000L), '0x1.ff\x9fp0', rep('0x1.ffffp0', 20000L)), f)
21559-
test(2334, names(fread(f)), "a")
21560-
unlink(f)
21557+
local({
21558+
f = tempfile()
21559+
on.exit(unlink(f))
21560+
# the line is likely invalid in current encoding, so disable any translation, #7209
21561+
# test.data.table() sets options(encoding="UTF-8"), so go the long way around.
21562+
ff = file(f, encoding = "")
21563+
tryCatch(
21564+
writeLines(c('a', rep('0x1.ffffp0', 10000L), `Encoding<-`('0x1.ff\x9fp0', 'bytes'), rep('0x1.ffffp0', 20000L)), ff),
21565+
finally = close(ff)
21566+
)
21567+
test(2334, names(fread(f)), "a")
21568+
})
2156121569

2156221570
# Tests for new isoyear() helper (complement to isoweek) #7154
2156321571
test(2335.1, isoyear(as.IDate("2019-12-30")), 2020L) # End of year edge case

0 commit comments

Comments
 (0)