Re: g_test_trap_fork() fails on g_return_...



Il giorno Mon, 8 Feb 2010 23:17:52 +0100
Nicola Fontana <ntd entidi it> ha scritto:

#include <glib.h>
#include <stdlib.h>

static void dummy(void)
{
    g_return_if_reached();
}

static void
test_trap_fork(void)
{
    if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR)) {
        dummy();
        exit(0);
    }
    g_test_trap_assert_passed();
}


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

    g_test_add_func("/trap_fork test", test_trap_fork);

    return g_test_run();
}


The above test fails (glib-2.22.4), no way to succesful returns after
a g_return_...() macro is encountered.

Answering to myself: g_test_init() always makes warnings and criticals
fatal [1]. A proper way to change this behaviour would be to use
g_test_log_set_fatal_handler() to install a new handler that ignores
log messages coming from the library domain: this works fine but pull
in a glib-2.22 dependency.

I ended up using g_log_set_always_fatal(0) instead, forcibly
disabling any fatal flag (apart g_error() ones, fatal by design).

-- 
Nicola


[1] http://git.gnome.org/browse/glib/tree/glib/gtestutils.c#n489



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]