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

Confusing result with expect_error() #726

Closed
BroVic opened this issue Mar 7, 2018 · 3 comments
Closed

Confusing result with expect_error() #726

BroVic opened this issue Mar 7, 2018 · 3 comments

Comments

@BroVic
Copy link

BroVic commented Mar 7, 2018

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.

@gaborcsardi
Copy link
Member

gaborcsardi commented Mar 7, 2018

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.

@BroVic
Copy link
Author

BroVic commented Mar 8, 2018

@gaborcsardi Yes, that did it. Thanks!

@BroVic BroVic closed this as completed Mar 8, 2018
@rvernica
Copy link

I kept getting bit by this. Maybe the error message can be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants