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

标签 c testing glib

我正在使用 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/

相关文章:

c# - 如何更改 Windows 程序中的主机文件?

c - scanf 不扫描 %c 字符而是跳过该语句,这是为什么?

testing - 最低精度的 ULP 单位

c# - 如何在 Visual Studio 2017 中使用 C# 使用 Selenium 查找和选择下拉值

c++ - 编译 gtk3 应用程序时出现 fatal error : glib. h 未找到

c++ - Ustring 错误(打印期间)

glib - glib中获取线程id(tid)

c - 从字符中提取位序列

ruby-on-rails - 使用 RSpec 测试嵌套资源会导致奇怪的失败

c - 在行号出现中生成第一个索引 '' 3 的函数''