From 69582bf63565c187a64daa1b9b22fc5a4d322db3 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 17 Aug 2013 14:14:20 -0400 Subject: [PATCH] Add a function to check test status from the inside The new g_test_failed() function can be used to find out if a currently running testcase is already marked as failed. https://bugzilla.gnome.org/show_bug.cgi?id=692125 --- glib/gtestutils.c | 24 ++++++++++++++++++++++++ glib/gtestutils.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 43756960e..086ff1dc8 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -1631,6 +1631,30 @@ g_test_skip (const gchar *msg) test_run_msg = g_strdup (msg); } +/** + * g_test_failed: + * + * Returns whether a test has already failed. This will + * be the case when g_test_fail(), g_test_incomplete() + * or g_test_skip() have been called, but also if an + * assertion has failed. + * + * This can be useful to return early from a test if + * continuing after a failed assertion might be harmful. + * + * The return value of this function is only meaningful + * if it is called from inside a test function. + * + * Returns: %TRUE if the test has failed + * + * Since: 2.38 + */ +gboolean +g_test_failed (void) +{ + return test_run_success != G_TEST_RUN_SUCCESS; +} + /** * GTestFunc: * diff --git a/glib/gtestutils.h b/glib/gtestutils.h index 446d722c7..30e07cab1 100644 --- a/glib/gtestutils.h +++ b/glib/gtestutils.h @@ -133,6 +133,8 @@ GLIB_AVAILABLE_IN_2_38 void g_test_incomplete (const gchar *msg); GLIB_AVAILABLE_IN_2_38 void g_test_skip (const gchar *msg); +GLIB_AVAILABLE_IN_2_38 +gboolean g_test_failed (void); /* hook up a test with fixture under test path */ #define g_test_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \