简体   繁体   English

谷歌死亡测试没有消息

[英]Google death tests without message

I am trying the Google Test framework on Linux and GCC10.我正在 Linux 和 GCC10 上尝试 Google 测试框架。

Basic tests work fine, however there is something about death tests I don't get.基本测试工作正常,但是我没有得到关于死亡测试的一些东西。 Death test macros like EXPECT_DEBUG_DEATH have a second parameter ("matcher") which should be a regex string that is compared to whatever has been printed to stderr before the test finishes by death of the process.EXPECT_DEBUG_DEATH这样的死亡测试宏有第二个参数(“matcher”),它应该是一个正则表达式字符串,它与在测试结束之前打印到stderr的任何内容进行比较。

TEST(MyDeathTests, MyDeathTest)
{
   EXPECT_DEBUG_DEATH({ assert(false); }, "");
   EXPECT_DEBUG_DEATH({ fprintf(stderr, "Bye\n"); fflush(stderr); exit(1); }, "");
   EXPECT_DEBUG_DEATH({ std::cerr << "Darn" << std::endl << std::flush; std::abort(); }, "");
}

Death is detected correctly.正确检测到死亡。 But tests succeed only when using an empty matcher string as you can see in the snippet above.但是只有在使用空匹配器字符串时测试才会成功,如您在上面的代码片段中所见。 "Actual msg" in the test output is always empty.测试 output 中的“实际味精”始终为空。 I tried some variants with exit() , stdout , stderr and C output functions but nothing worked.我尝试了一些带有exit()stdoutstderr和 C output 函数的变体,但没有任何效果。

Any ideas why no death messages are received?任何想法为什么没有收到死亡消息?

Turned out there have been two misunderstandings on my side:原来我这边有两个误解:

  1. The matcher-strings are sub-string patterns.匹配器字符串是子字符串模式。 This means an empty matcher-string matches anything (not only empty messages as assumed by me).这意味着一个空的匹配器字符串匹配任何东西(不仅仅是我假设的空消息)。
  2. Actual msg did not really display an empty message string. Actual msg并没有真正显示空消息字符串。 It only uses a weird formatting.它只使用一种奇怪的格式。 Google test adds a line break followed by [ DEATH ] after Actual msg before printing the error message.谷歌测试在打印错误消息之前在Actual msg之后添加一个换行符,然后是[ DEATH ] This made me think I would see the un-caught error output on the console but actually it was the correctly detected Actual msg .这让我觉得我会在控制台上看到未捕获的错误 output 但实际上它是正确检测到的Actual msg

Knowing those facts, everything works as expected.知道了这些事实,一切都按预期进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM