Hi,
I obtained this confusing result when trying to use the expect_error()
function as follows:
> expect_error(build_report(9), "is.character(file) is not TRUE")
Error: `build_report(9)` threw an error with unexpected message.
Expected match: "is.character(file) is not TRUE"
Actual message: "is.character(file) is not TRUE"
The function I'm testing has a quick validation check that looks like this
...
stopifnot(is.character(file))
...
To make sure that it wasn't my vision playing tricks on me, I copied both expectations from the output and pasted them into identical()
and sure enough the result was TRUE
.
Have I gone wrong somewhere or is this a bug?
Regards.
Quick guess: the matching string is a regular expression. Do
expect_error(build_report(9), "is.character(file) is not TRUE", fixed = TRUE)
to avoid having to write regexes.
@gaborcsardi Yes, that did it. Thanks!
I kept getting bit by this. Maybe the error message can be improved.
Most helpful comment
Quick guess: the matching string is a regular expression. Do
to avoid having to write regexes.