I am developing a package and I have written tests using the expect_error function from the testthat package. I am using its 'regexp' argument to check whether the correct error is thrown. My test looks like this:
test_that('weird localization issue', {
skip_if_translated()
expect_error(if (logical(0)) {print("yes")} else {print("no")}, "argument is of length zero")
})
If I run devtools::test()
in the RStudio console, all tests pass. If I use Ctrl + Alt + T, the tests fail. The actual message is the German translation of the expected message:
test_cmsaf.add.R:482: failure: weird localization issue
`if (...) NULL` threw an error with unexpected message.
Expected match: "argument is of length zero"
Actual message: "Argument hat L�nge 0"
My questions are the following:
- Why do the two ways of running tests behave differently?
- How can I prevent RStudio from automatically translating error messages?
- Why does the function
skip_if_translated()
not work as I expect it to? - Who is responsible for � being shown instead of the German Umlaut in the actual message?
This is the first part of the output of sessionInfo()
:
> sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
I use version 2.0.1 of testthat and RStudio version 1.1.463.