Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding on windows with expect_known_output #694

Closed
tklebel opened this issue Dec 19, 2017 · 8 comments
Closed

encoding on windows with expect_known_output #694

tklebel opened this issue Dec 19, 2017 · 8 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@tklebel
Copy link

tklebel commented Dec 19, 2017

I'm having difficulties with expect_known_output on windows due to encoding issues. The reference file was created on unix, and tests pass there. On windows several tests fail. I checked the ouput of my functions, it is UTF-8, so there is no reason why a mismatch between output and reference file should occur.

There seems to be a problem in testthat, as the following reprex suggests:

library(testthat)

text <- c("Acohido “ Snowden")
file <- tempfile()

expect_known_output(text, file, print = T, update = FALSE)
#> Warning: Creating reference output
expect_known_output(text, file, print = T, update = FALSE)
#> Error: `text` has changed from known value recorded in 'C:\\Users\\...'.
#> 1/1 mismatches
#> x[1]: "[1] \"Acohido “ Snowden\""
#> y[1]: "[1] \"Acohido “ Snowden\""
@gaborcsardi
Copy link
Member

What's your testthat version?

@tklebel
Copy link
Author

tklebel commented Dec 19, 2017

2.0.0. Current dev version does not work for me either.

@gaborcsardi
Copy link
Member

gaborcsardi commented Dec 19, 2017

Looks like this is a bug indeed. The strings are actually equal, but they have different marked encodings, one is "unknown", the other one "latin1". I don't have an immediate workaround unfortunately, except for using expect_output, or capture.output.

@patperry
Copy link

This might be related to a bug in R that is fixed in R-devel: wch/r-source@64f889d . (enc2utf8/translateCharUTF8 is broken for Windows native strings for characters in CP1252 that aren't Latin-1, like curly quotes.) You can probably use utf8::as_utf8 to work around this if you need something that works in older versions of R. Alternatively, compare expected output by translating to native encoding, not by translating to UTF-8.

@gaborcsardi
Copy link
Member

@patperry they don't seem related to me.

@patperry
Copy link

you know better than I do. any time I see a curly quote and "Windows encoding" I assume it's this CP1252/Latin-1 issue

@jimhester jimhester added the bug an unexpected problem or unintended behavior label Mar 29, 2018
@jonthegeek
Copy link
Contributor

I do not get the bug output with testthat 2.0.1 and R 3.5.1 on Windows.

@hadley
Copy link
Member

hadley commented Mar 28, 2019

Closing since it seems like this has fixed itself in the mean time.

@hadley hadley closed this as completed Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

6 participants