[英]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:我正在使用 catch2(最新版本 - 2.13.6 截至目前),在我的测试用例中,我有一堆类似于以下的检查:
CHECK(!strcmp(my_str, "some literal string here"));
where the literal is different for each testcase and obviously so is my_str
's contents.每个测试用例的文字都不同,显然my_str
的内容也是如此。
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.但我没有打印出my_str
的搅拌。 What's the best way to get the above to print (some of) the contents of my_str
as well?让上述内容也打印(部分) my_str
的内容的最佳方法是什么?
Notes:笔记:
my_str
is null-terminated.您可能不会假设my_str
是以空值结尾的。std::string
, but if you must do that, I'm not ruling it out.我宁愿不将任何内容转换为std::string
,但如果您必须这样做,我不排除它。My own hacky solution is the following:我自己的hacky解决方案如下:
#define PRINTING_CHECK(expected_, actual_) \
do { \
INFO( "actual_ = " << '"' << actual_ << '"'); \
CHECK(!strcmp(actual_, expected_)); \
} while (false) \
but I was hoping there might be something more elegant.但我希望可能有更优雅的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.