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

Not respecting zero byte (\0) while logging mismatch of std::string. #140

Closed
OpatrilPeter opened this issue Apr 29, 2019 · 3 comments
Closed
Labels
third-party Due to a third-party issue or user error

Comments

@OpatrilPeter
Copy link

In current solution, following code

AssertThat("abc\0def"s, Equals("abc"));

leads to error:

There were failures!

Test ....:
...: Expected: equal to abc
Actual: abc

(IMHO it should print what printing the std::string would - abcdef - or in ideal world, something like abc\x00def)
The message for the exception is generated correctly, problem lies in printing it in failure_formatter: it uses what() method which returns const char *, so it simply ends on first \0 occurence.

@sbeyer
Copy link
Member

sbeyer commented Apr 29, 2019

Yes, the C++ standard defines what() to return a null-terminated const char * string, hence the issue cannot be solved on that end. One could make a default-Stringizer for strings in Snowhouse that converts non-printable characters (like \0) to something printable. I am however not sure if this is always desirable...

@OpatrilPeter
Copy link
Author

As I see it, a major use of this Stringizer is to be able to compare values, thus it seems like a sensible default to highlight otherwise undetectable differences.

@sbeyer
Copy link
Member

sbeyer commented Mar 29, 2020

I close this issue here; the respective issue is in Snowhouse (banditcpp/snowhouse#40). However, I have no idea when I get to it.

@sbeyer sbeyer closed this as completed Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
third-party Due to a third-party issue or user error
Projects
None yet
Development

No branches or pull requests

2 participants