C++ 当断言失败时仅显示差异

C++ 当断言失败时仅显示差异,c++,googletest,C++,Googletest,当googletest的断言失败时,它会同时打印输入字符串及其差异。我能让它只打印差异吗?只使用GTest功能吗?据我所知不是这样 但是,没有什么能阻止您编写自己的比较函数,即 bool stringsMatch(std::string oneString, std::string otherString) { //... }; std::string getDifferencesBetween(std::string oneString, std::string otherStrin

当googletest的断言失败时,它会同时打印输入字符串及其差异。我能让它只打印差异吗?

只使用GTest功能吗?据我所知不是这样

但是,没有什么能阻止您编写自己的比较函数,即

bool stringsMatch(std::string oneString, std::string otherString)
{
    //...
};

std::string getDifferencesBetween(std::string oneString, std::string otherString)
{
    //...
};
然后写

//...
if (!stringsMatch(actualString, expectedString))
{
    FAIL() << getDifferencesBetween(actualString, expectedString);
}
//...
/。。。
如果(!stringsMatch(实际字符串、预期字符串))
{

出于好奇而失败:为什么?您可以编写自己的匹配程序,并在
断言(actualString,StringMatchShowingOnlyDiff(expectedString));
中使用它。。。