[glib] gtestutils: fix g_test_set_nonfatal_assertions()
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gtestutils: fix g_test_set_nonfatal_assertions()
- Date: Sun, 24 Nov 2013 20:14:37 +0000 (UTC)
commit f4c30feb9598e09d1d32805bad96e216c1a21786
Author: Dan Winship <danw gnome org>
Date: Sun Nov 10 15:44:06 2013 -0500
gtestutils: fix g_test_set_nonfatal_assertions()
g_test_set_nonfatal_assertions() was a no-op, because
g_assertion_message() wasn't actually checking the
test_nonfatal_assertions flag. Fix that and add a test.
Also, g_test_set_nonfatal_assertions() has to set test_mode_fatal to
FALSE as well, or else a failed assertion will cause the test program
to abort at the end of the failed test.
Also, belatedly add this and the new g_assert_* methods to the docs.
https://bugzilla.gnome.org/show_bug.cgi?id=711800
docs/reference/glib/glib-sections.txt | 5 +++++
glib/gtestutils.c | 19 +++++++++++++++----
glib/tests/testing.c | 22 ++++++++++++++++++++++
3 files changed, 42 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index ae5df60..4b25549 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -2966,6 +2966,7 @@ g_test_rand_double_range
g_assert
g_assert_not_reached
+
g_assert_cmpstr
g_assert_cmpint
g_assert_cmpuint
@@ -2973,6 +2974,10 @@ g_assert_cmphex
g_assert_cmpfloat
g_assert_no_error
g_assert_error
+g_assert_true
+g_assert_false
+g_assert_null
+g_test_set_nonfatal_assertions
GTestCase
GTestSuite
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index 34cee4d..7da2fc0 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -1754,7 +1754,9 @@ g_test_failed (void)
* 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.
+ * 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.
@@ -1769,6 +1771,7 @@ g_test_set_nonfatal_assertions (void)
if (!g_test_config_vars->test_initialized)
g_error ("g_test_set_nonfatal_assertions called without g_test_init");
test_nonfatal_assertions = TRUE;
+ test_mode_fatal = FALSE;
}
/**
@@ -2271,15 +2274,23 @@ g_assertion_message (const char *domain,
" ", message, NULL);
g_printerr ("**\n%s\n", s);
+ g_test_log (G_TEST_LOG_ERROR, s, NULL, 0, NULL);
+
+ if (test_nonfatal_assertions)
+ {
+ g_free (s);
+ g_test_fail ();
+ return;
+ }
+
/* store assertion message in global variable, so that it can be found in a
* core dump */
if (__glib_assert_msg != NULL)
- /* free the old one */
- free (__glib_assert_msg);
+ /* free the old one */
+ free (__glib_assert_msg);
__glib_assert_msg = (char*) malloc (strlen (s) + 1);
strcpy (__glib_assert_msg, s);
- g_test_log (G_TEST_LOG_ERROR, s, NULL, 0, NULL);
g_free (s);
_g_log_abort ();
}
diff --git a/glib/tests/testing.c b/glib/tests/testing.c
index 90f11bb..3a89370 100644
--- a/glib/tests/testing.c
+++ b/glib/tests/testing.c
@@ -563,6 +563,25 @@ test_dash_p (void)
g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden*");
}
+static void
+test_nonfatal_subprocess (void)
+{
+ g_test_set_nonfatal_assertions ();
+
+ g_assert_cmpint (4, ==, 5);
+
+ g_print ("The End\n");
+}
+
+static void
+test_nonfatal (void)
+{
+ g_test_trap_subprocess ("/misc/nonfatal/subprocess", 0, 0);
+ g_test_trap_assert_failed ();
+ g_test_trap_assert_stderr ("*assertion failed*4 == 5*");
+ g_test_trap_assert_stdout ("*The End*");
+}
+
int
main (int argc,
char *argv[])
@@ -624,5 +643,8 @@ main (int argc,
g_test_add_func ("/misc/dash-p/subprocess/hidden", test_dash_p_hidden);
g_test_add_func ("/misc/dash-p/subprocess/hidden/sub", test_dash_p_hidden_sub);
+ g_test_add_func ("/misc/nonfatal", test_nonfatal);
+ g_test_add_func ("/misc/nonfatal/subprocess", test_nonfatal_subprocess);
+
return g_test_run();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]