'How to get catch2 to print the compared C-style string's contents?
I'm using catch2 (latest release - 2.13.6 as of this moment), and in my testcases I have a bunch of checks similar to the following:
CHECK(!strcmp(my_str, "some literal string here"));
where the literal is different for each testcase and obviously so is my_str's contents.
When such a check fails, what I get on the output is the following:
/path/to/test_source_file.cpp:123: FAILED:
CHECK( !strcmp(my_str, "some literal string here") )
with expansion:
false
but I don't get the stirng within my_str printed out. What's the best way to get the above to print (some of) the contents of my_str as well?
Notes:
- You may not assume
my_stris null-terminated. - Code must relatively succinct.
- I would rather not convert anything to an
std::string, but if you must do that, I'm not ruling it out.
Solution 1:[1]
My own hacky solution is the following:
#define PRINTING_CHECK(expected_, actual_) \
do { \
INFO( "actual_ = " << '"' << actual_ << '"'); \
INFO( "expected_ = " << '"' << expected_ << '"'); \
CHECK(!strcmp(actual_, expected_)); \
} while (false) \
but I was hoping there might be something more elegant.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
