I have some particularly finicky code that behaves differently on different platforms, but also behaves differently if run under valgrind
... right now I know that it
- gives a warning if run on 32-bit Linux not under valgrind
- gives an error if run elsewhere or on 32-bit Linux with
R -d valgrind
The code below works (sorry for the lack of reproducible example, you can probably see that it would be pretty hard to write one) if I'm not running under valgrind
, but under valgrind
it fails because we get an error rather than a warning.
if (sessionInfo()$platform=="i686-pc-linux-gnu (32-bit)") {
expect_warning(update(g0, .~. +year), "failed to converge")
} else {
expect_error(update(g0, .~. +year), "pwrssUpdate did not converge in")
}
I would like an expect_warning_or_error()
function; I suppose I could make one by hacking together the guts of expect_error
and expect_warning
, which don't look too complicated, but I welcome other suggestions.
Alternatively, I could figure out how to detect whether I am running under valgrind
or not (seems harder).
A sort-of reproducible example:
library(testthat)
for (i in c("warning","stop")) {
expect_warning(get(i)("foo"))
expect_error(get(i)("foo"))
}