[glib] Add a function to check test status from the inside



commit 69582bf63565c187a64daa1b9b22fc5a4d322db3
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 17 14:14:20 2013 -0400

    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(+), 0 deletions(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index 4375696..086ff1d 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -1632,6 +1632,30 @@ g_test_skip (const gchar *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:
  *
  * The type used for test case functions.
diff --git a/glib/gtestutils.h b/glib/gtestutils.h
index 446d722..30e07ca 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) \


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