0

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_str is 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.
einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

0

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.

einpoklum
  • 118,144
  • 57
  • 340
  • 684