g_test_set_nonfatal_assertions() still Aborted (core dump) when using glib test framework

StackOverflow https://stackoverflow.com/questions/22669182

  •  21-06-2023
  •  | 
  •  

Pregunta

I am writing tests using the glib testing framework. They have assertions such as g_assert_true, which in their documentation says:

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() is defined as:

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().

This implies by calling g_test_set_nonfatal_assertions, rather than the test program to shut down it should continue running, it should continue running and mark the testcase as failed. However I have the following code snippet:

    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(); 
}

I get the following output:

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

Given the documentation you would expect it not to be Aborted. It seems to me that g_test_set_nonfatal_assertions() is just not working. Does anyone know if this is an existing bug, or if I am missing a step?

¿Fue útil?

Solución

It's a known issue that cannot be easily fixed without actually running each separate test unit in a separate process.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top