gpt4 book ai didi

c - 使用 glib 测试框架时,g_test_set_nonfatal_assertions() 仍然中止(核心转储)

转载 作者:太空宇宙 更新时间:2023-11-04 02:50:29 26 4
gpt4 key购买 nike

我正在使用 glib 测试框架编写测试。他们有诸如 g_assert_true 之类的断言,在他们的文档中说:

Debugging macro to check that an expression is true. If the assertion fails (i.e. the expression is not true), an error message is logged and the application is either terminated or the testcase marked as failed. See g_test_set_nonfatal_assertions().

g_test_set_nonfatal_assertions() 定义为:

Changes the behaviour of g_assert_cmpstr(), g_assert_cmpint(), g_assert_cmpuint(), g_assert_cmphex(), g_assert_cmpfloat(), g_assert_true(), g_assert_false(), g_assert_null(), g_assert_no_error(), g_assert_error(), g_test_assert_expected_messages() and the various g_test_trap_assert_*() macros to not abort to program, but instead call g_test_fail() and continue. (This also changes the behavior of g_test_fail() so that it will not cause the test program to abort after completing the failed test.) Note that the g_assert_not_reached() and g_assert() are not affected by this. This function can only be called after g_test_init().

这意味着通过调用 g_test_set_nonfatal_assertions,而不是关闭它的测试程序应该继续运行,它应该继续运行并将测试用例标记为失败。但是我有以下代码片段:

    void test_subscribe(mfixture* mf, gconstpointer ignored)
{
g_assert_true(FALSE);
}

void test_test(mfixture* mf, gconstpointer ignored)
{
}


int main(int argc, char **argv){
g_test_init(&argc, &argv, NULL);
g_test_set_nonfatal_assertions ();

g_test_add ("/set1/subscribe test", mfixture, NULL,message_setup, test_subscribe, message_teardown);
g_test_add ("/set1/test test", mfixture, NULL,message_setup, test_test, message_teardown);


return g_test_run();
}

我得到以下输出:

ERROR:HubSubscriptions_test.c:32:test_subscribe: FALSE make: * [test-all] Aborted (core dumped)

鉴于文档,您可能希望它不会被中止。在我看来,g_test_set_nonfatal_assertions() 只是不起作用。有谁知道这是否是一个现有错误,或者我是否遗漏了一个步骤?

最佳答案

a known issue如果不在单独的进程中实际运行每个单独的测试单元,就无法轻易修复。

关于c - 使用 glib 测试框架时,g_test_set_nonfatal_assertions() 仍然中止(核心转储),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22669182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com