Hi,
I've got a function that throws an error (expected). Despite the expected and actual messages looking identical, the test fails due to the 'unexpected' message.
I think it might have to do with the deparse(substitute(x))
call since when I avoid getting the expression as a string, the test works as expected
library(testthat)
library(cli)
assertdataframe <- function(x) {
string_argname <- deparse(substitute(x))
if (!is.data.frame(x)) {
cli_abort("Error: '{string_argname}' is not a data frame! Object class: {class(x)}")
}
invisible(TRUE)
}
expect_error(assertdataframe(list(x = 1:5, y = 6:10)), "Error: 'list(x = 1:5, y = 6:10)' is not a data frame! Object class: list")
#> Error: `assertdataframe(list(x = 1:5, y = 6:10))` threw an error with unexpected message.
#> Expected match: "Error: 'list(x = 1:5, y = 6:10)' is not a data frame! Object class: list"
#> Actual message: "Error: 'list(x = 1:5, y = 6:10)' is not a data frame! Object class: list"
Created on 2023-01-03 with reprex v2.0.2
Any ideas about why this test fails?