banditcpp / bandit

Human-friendly unit testing for C++11
https://banditcpp.github.io/bandit/
Other
259 stars 37 forks source link

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

Closed OpatrilPeter closed 4 years ago

OpatrilPeter commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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