Comparison failures should display unprintable characters in strings
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
String comparison takes into account *all* characters, including non-printable ones like NUL, BEL, ESC and so on. Yet when such a comparison fails, Catch only displays printable characters; aforementioned NUL, BEL, ESC etc. are not displayed at all. This can lead to confusing output where *displayed* strings are equivalent while *actual* strings aren't.
**Expected behavior**
I expect Catch to display non-printable characters via escape codes, just as I'd write those characters in C++.
**Reproduction steps**
```c++
#include
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE("Fails")
{
const std::string string1("abc\0", 4);
const std::string string2("abc", 3);
REQUIRE(string1 == string2);
}
```
Example output:
```
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.out is a Catch v2.12.1 host application.
Run with -? for options
-------------------------------------------------------------------------------
Fails
-------------------------------------------------------------------------------
example.cpp:6
...............................................................................
example.cpp:11: FAILED:
REQUIRE( string1 == string2 )
with expansion:
"abc" == "abc"
===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed
```
An output like `"abc\0" == "abc"` would be less confusing.
**Platform information:**
- OS: **Debian testing, up-to-date as of May 13th, 2020**
- Compiler+version: **GCC 9.3.0**
- Catch version: **v2.12.1**
**Additional context**
This seems slightly related to https://github.com/catchorg/Catch2/issues/1116.
Contributor guide
Assessment
This issue has not been assessed yet.