[EXPECT_NO_DEATH()在Google测试中

问题描述 投票:1回答:1

有一些有用的EXPECT_DEATH()和规则族可以按预期检查程序的运行,但是是否设置了负EXPECT_NO_DEATH()或类似的值?举一个人工的例子:

void should_i_die(bool die)
{
    if (die) { printf("Aaargh!"); exit(-1); }
    else       printf("I'm not dead yet!");
}

EXPECT_DEATH(should_i_die(true), "Aaargh.*");
EXPECT_NO_DEATH(should_i_die(false), ".*"); // What should be here?

仅具有独立版本:

should_i_die(false);
EXPECT_TRUE(true); // We're not dead if we reach here

感觉有点像傻瓜,所以有更好的方法吗?

c++ exit googletest
1个回答
0
投票

我认为类似的方法应该可以工作(尽管我自己还没有尝试过。)>

EXPECT_EXIT({should_i_die(false); fprintf(stderr, "Still alive!"); exit(0);},
    ::testing::ExitedWithCode(0), "Still alive!");

需要退出,因为AFAICT,活到死亡测试结束就被视为失败。

© www.soinside.com 2019 - 2024. All rights reserved.