r23289 - gnucash/trunk/src - Adjust error-message tests to pass with Clang

John Ralls jralls at code.gnucash.org
Wed Oct 9 01:28:16 EDT 2013


Author: jralls
Date: 2013-10-09 01:28:15 -0400 (Wed, 09 Oct 2013)
New Revision: 23289
Trac: http://svn.gnucash.org/trac/changeset/23289

Modified:
   gnucash/trunk/src/engine/test/test-object.c
   gnucash/trunk/src/engine/test/utest-Account.c
   gnucash/trunk/src/engine/test/utest-Split.c
   gnucash/trunk/src/engine/test/utest-Transaction.c
   gnucash/trunk/src/libqof/qof/qofbook.c
   gnucash/trunk/src/libqof/qof/qoflog.c
   gnucash/trunk/src/libqof/qof/test/test-gnc-date.c
   gnucash/trunk/src/libqof/qof/test/test-qofbook.c
Log:
Adjust error-message tests to pass with Clang

Clang emits full function signatures for __func__ where GCC emits
only the function name.
Adjust Gnucash's own error messages emitted via PWARN and friends
to trim the extra bits so that only the function name is emitted
regardless of compiler. For messages emitted directly by glib
(usually from g_return_if_fail macros), the message in the test
case is special-cased for Clang so that it matches and the test
passes.

Modified: gnucash/trunk/src/engine/test/test-object.c
===================================================================
--- gnucash/trunk/src/engine/test/test-object.c	2013-10-09 05:28:02 UTC (rev 23288)
+++ gnucash/trunk/src/engine/test/test-object.c	2013-10-09 05:28:15 UTC (rev 23289)
@@ -40,27 +40,16 @@
 
 static QofObject bus_obj =
 {
-interface_version:
     QOF_OBJECT_VERSION,
-e_type:
     TEST_MODULE_NAME,
-type_label:
     TEST_MODULE_DESC,
-create:
     NULL,
-book_begin:
     NULL,
-book_end:
     NULL,
-is_dirty:
     NULL,
-mark_clean:
     NULL,
-foreach:
     obj_foreach,
-printable:
     printable,
-version_cmp:
     NULL,
 };
 

Modified: gnucash/trunk/src/engine/test/utest-Account.c
===================================================================
--- gnucash/trunk/src/engine/test/utest-Account.c	2013-10-09 05:28:02 UTC (rev 23288)
+++ gnucash/trunk/src/engine/test/utest-Account.c	2013-10-09 05:28:15 UTC (rev 23289)
@@ -462,7 +462,13 @@
 {
     guint log_level = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
     gchar *log_domain = "gnc.engine";
-    gchar *msg = "gnc_account_list_name_violations: assertion " _Q "separator != NULL' failed";
+#ifdef __clang__
+#define _func "GList *gnc_account_list_name_violations(QofBook *, const gchar *)"
+#else
+#define _func "gnc_account_list_name_violations"
+#endif
+    gchar *msg = _func ": assertion " _Q "separator != NULL' failed";
+#undef _func
     TestErrorStruct check = { log_level, log_domain, msg, 0 };
     GList *results, *res_iter;
     gchar *sep = ":";
@@ -743,8 +749,14 @@
     Account *clone;
     QofBook *book = gnc_account_get_book (fixture->acct);
     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
-    gchar *msg1 = "xaccCloneAccount: assertion " _Q "GNC_IS_ACCOUNT(from)' failed";
-    gchar *msg2 = "xaccCloneAccount: assertion " _Q "QOF_IS_BOOK(book)' failed";
+#ifdef __clang__
+#define _func "Account *xaccCloneAccount(const Account *, QofBook *)"
+#else
+#define _func "xaccCloneAccount"
+#endif
+    gchar *msg1 = _func ": assertion " _Q "GNC_IS_ACCOUNT(from)' failed";
+    gchar *msg2 = _func ": assertion " _Q "QOF_IS_BOOK(book)' failed";
+#undef _func
     TestErrorStruct check = { loglevel, "gnc.engine", msg1, 0 };
     GLogFunc oldlogger;
     AccountPrivate *acct_p, *clone_p;
@@ -840,7 +852,13 @@
 {
     gchar *msg1 = "[xaccFreeAccount()]  instead of calling xaccFreeAccount(), please call \n"
                   " xaccAccountBeginEdit(); xaccAccountDestroy(); \n";
-    gchar *msg2 = "xaccTransGetSplitIndex: assertion " _Q "trans && split' failed";
+#ifdef __clang__
+#define _func "int xaccTransGetSplitIndex(const Transaction *, const Split *)"
+#else
+#define _func "xaccTransGetSplitIndex"
+#endif
+    gchar *msg2 = _func ": assertion " _Q "trans && split' failed";
+#undef _func
     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
     TestErrorStruct check1 = { loglevel, "gnc.account", msg1, 0 };
     TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 };
@@ -948,7 +966,13 @@
 {
     gchar *msg1 = "[xaccFreeAccount()]  instead of calling xaccFreeAccount(), please call \n"
                   " xaccAccountBeginEdit(); xaccAccountDestroy(); \n";
-    gchar *msg2 = "xaccTransGetSplitIndex: assertion " _Q "trans && split' failed";
+#ifdef __clang__
+#define _func "int xaccTransGetSplitIndex(const Transaction *, const Split *)"
+#else
+#define _func "xaccTransGetSplitIndex"
+#endif
+    gchar *msg2 = _func ": assertion " _Q "trans && split' failed";
+#undef _func
     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
     TestErrorStruct check1 = { loglevel, "gnc.account", msg1, 0 };
     TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 };
@@ -1059,8 +1083,14 @@
     Split *split3 = xaccMallocSplit (book);
     TestSignal sig1, sig2, sig3;
     AccountPrivate *priv = fixture->func->get_private (fixture->acct);
-    gchar *msg1 = "gnc_account_insert_split: assertion " _Q "GNC_IS_ACCOUNT(acc)' failed";
-    gchar *msg2 = "gnc_account_insert_split: assertion " _Q "GNC_IS_SPLIT(s)' failed";
+#ifdef __clang__
+#define _func "gboolean gnc_account_insert_split(Account *, Split *)"
+#else
+#define _func "gnc_account_insert_split"
+#endif
+    gchar *msg1 = _func ": assertion " _Q "GNC_IS_ACCOUNT(acc)' failed";
+    gchar *msg2 = _func ": assertion " _Q "GNC_IS_SPLIT(s)' failed";
+#undef _func
     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
 //    gchar *log_domain = "gnc.engine";
     TestErrorStruct check1 = { loglevel, "gnc.engine", msg1, 0 };

Modified: gnucash/trunk/src/engine/test/utest-Split.c
===================================================================
--- gnucash/trunk/src/engine/test/utest-Split.c	2013-10-09 05:28:02 UTC (rev 23288)
+++ gnucash/trunk/src/engine/test/utest-Split.c	2013-10-09 05:28:15 UTC (rev 23289)
@@ -1268,7 +1268,13 @@
     Account *acc1 = xaccMallocAccount (book);
     Account *acc2 = xaccMallocAccount (book);
     Account *acc3 = xaccMallocAccount (book);
-    gchar *msg = "get_corr_account_split: assertion " _Q "sa' failed";
+#ifdef __clang__
+#define _func "gboolean get_corr_account_split(const Split *, const Split **)"
+#else
+#define _func "get_corr_account_split"
+#endif
+    gchar *msg = _func ": assertion " _Q "sa' failed";
+#undef _func
     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
     TestErrorStruct *check = test_error_struct_new ("gnc.engine",
 						    loglevel, msg);

Modified: gnucash/trunk/src/engine/test/utest-Transaction.c
===================================================================
--- gnucash/trunk/src/engine/test/utest-Transaction.c	2013-10-09 05:28:02 UTC (rev 23288)
+++ gnucash/trunk/src/engine/test/utest-Transaction.c	2013-10-09 05:28:15 UTC (rev 23289)
@@ -486,7 +486,13 @@
     QofBook *book = qof_book_new ();
     TestSignal sig1 = test_signal_new (NULL, QOF_EVENT_CREATE,NULL);
     Transaction *txn;
-    gchar *msg = "xaccMallocTransaction: assertion " _Q "book' failed";
+#ifdef __clang__
+#define _func "Transaction *xaccMallocTransaction(QofBook *)"
+#else
+#define _func "xaccMallocTransaction"
+#endif
+    gchar *msg = _func ": assertion " _Q "book' failed";
+#undef _func
     gchar *logdomain = "gnc.engine";
     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
     TestErrorStruct *check = test_error_struct_new ("gnc.engine", loglevel,
@@ -1265,7 +1271,13 @@
 static void
 test_xaccTransGetAccountBalance (Fixture *fixture, gconstpointer pData)
 {
-    gchar *msg1 = "xaccTransGetAccountBalance: assertion " _Q "account && trans' failed";
+#ifdef __clang__
+#define _func "gnc_numeric xaccTransGetAccountBalance(const Transaction *, const Account *)"
+#else
+#define _func "xaccTransGetAccountBalance"
+#endif
+    gchar *msg1 = _func ": assertion " _Q "account && trans' failed";
+#undef _func
     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
     TestErrorStruct *check = test_error_struct_new ("gnc.engine", loglevel,
 						    msg1);

Modified: gnucash/trunk/src/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.c	2013-10-09 05:28:02 UTC (rev 23288)
+++ gnucash/trunk/src/libqof/qof/qofbook.c	2013-10-09 05:28:15 UTC (rev 23289)
@@ -194,7 +194,7 @@
 qof_book_print_dirty (const QofBook *book)
 {
     if (qof_book_session_not_saved(book))
-        printf("book is dirty.\n");
+        PINFO("book is dirty.");
     qof_book_foreach_collection
     (book, (QofCollectionForeachCB)qof_collection_print_dirty, NULL);
 }
@@ -209,7 +209,7 @@
 qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data)
 {
     if (book->dirty_cb)
-        g_warning("qof_book_set_dirty_cb: Already existing callback %p, will be overwritten by %p\n",
+        PWARN("Already existing callback %p, will be overwritten by %p\n",
                   book->dirty_cb, cb);
     book->dirty_data = user_data;
     book->dirty_cb = cb;
@@ -692,7 +692,7 @@
 
     if (kvp_val == NULL)
     {
-        //g_warning("kvp_val for slot '%s' is NULL", OPTION_NAME_AUTO_READONLY_DAYS);
+        //PWARN("kvp_val for slot '%s' is NULL", OPTION_NAME_AUTO_READONLY_DAYS);
         return 0;
     }
 

Modified: gnucash/trunk/src/libqof/qof/qoflog.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qoflog.c	2013-10-09 05:28:02 UTC (rev 23288)
+++ gnucash/trunk/src/libqof/qof/qoflog.c	2013-10-09 05:28:15 UTC (rev 23289)
@@ -51,6 +51,7 @@
 #include "qoflog.h"
 
 #define QOF_LOG_MAX_CHARS 50
+#define QOF_LOG_MAX_CHARS_WITH_ALLOWANCE 100
 #define QOF_LOG_INDENT_WIDTH 4
 #define NUM_CLOCKS 10
 
@@ -238,28 +239,33 @@
 const char *
 qof_log_prettify (const char *name)
 {
-    gchar *p, *buffer;
+    gchar *p, *buffer, *begin;
     gint length;
 
     if (!name)
     {
         return "";
     }
-    buffer = g_strndup(name, QOF_LOG_MAX_CHARS - 1);
+/* Clang's __func__ displays the whole signature, like a good C++
+ * compier should. Gcc displays only the name of the function. Strip
+ * the extras from Clang's output so that log messages are the same
+ * regardless of compiler.
+ */
+    buffer = g_strndup(name, QOF_LOG_MAX_CHARS_WITH_ALLOWANCE - 1);
     length = strlen(buffer);
-    p = g_strstr_len(buffer, length, "(");
-    if (p)
-    {
-        *(p + 1) = ')';
-        *(p + 2) = 0x0;
-    }
+    p = g_strstr_len (buffer, length, "(");
+    if (p) *p = '\0';
+    begin = g_strrstr (buffer, "*");
+    if (begin == NULL)
+	begin = g_strrstr (buffer, " ");
+    if (begin != NULL)
+	p = begin + 1;
     else
-    {
-        strcpy (&buffer[QOF_LOG_MAX_CHARS - 6], "...()");
-    }
+	p = buffer;
+
     if (function_buffer)
         g_free(function_buffer);
-    function_buffer = g_strdup(buffer);
+    function_buffer = g_strdup(p);
     g_free(buffer);
     return function_buffer;
 }

Modified: gnucash/trunk/src/libqof/qof/test/test-gnc-date.c
===================================================================
--- gnucash/trunk/src/libqof/qof/test/test-gnc-date.c	2013-10-09 05:28:02 UTC (rev 23288)
+++ gnucash/trunk/src/libqof/qof/test/test-gnc-date.c	2013-10-09 05:28:15 UTC (rev 23289)
@@ -69,7 +69,13 @@
                                   // difference between g_date_time and tm->tm_wday)
                      };
     guint ind;
-    gchar *msg = "gnc_localtime_r: assertion " _Q "gdt != NULL' failed";
+#ifdef __clang__
+#define _func "struct tm *gnc_localtime_r(const time64 *, struct tm *)"
+#else
+#define _func "gnc_localtime_r"
+#endif
+    gchar *msg = _func ": assertion " _Q "gdt != NULL' failed";
+#undef _func
     gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
     gchar *logdomain = "qof";
     TestErrorStruct check = {loglevel, logdomain, msg, 0};
@@ -132,7 +138,13 @@
 #endif
     };
     guint ind;
-    gchar *msg = "gnc_gmtime: assertion " _Q "gdt != NULL' failed";
+#ifdef __clang__
+#define _func "struct tm *gnc_gmtime(const time64 *)"
+#else
+#define _func "gnc_gmtime"
+#endif
+    gchar *msg = _func ": assertion " _Q "gdt != NULL' failed";
+#undef _func
     gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
     gchar *logdomain = "qof";
     TestErrorStruct check = {loglevel, logdomain, msg, 0};
@@ -1695,7 +1707,13 @@
     gchar *end;
     gchar *logdomain = "qof";
     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
-    gchar *msg = "gnc_timespec_to_iso8601_buff: assertion " _Q "buff != NULL' failed";
+#ifdef __clang__
+#define _func "gchar *gnc_timespec_to_iso8601_buff(Timespec, char *)"
+#else
+#define _func "gnc_timespec_to_iso8601_buff"
+#endif
+    gchar *msg = _func ": assertion " _Q "buff != NULL' failed";
+#undef _func
     TestErrorStruct check = { loglevel, logdomain, msg, 0 };
     GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler,
 						    &check);

Modified: gnucash/trunk/src/libqof/qof/test/test-qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/test/test-qofbook.c	2013-10-09 05:28:02 UTC (rev 23288)
+++ gnucash/trunk/src/libqof/qof/test/test-qofbook.c	2013-10-09 05:28:15 UTC (rev 23289)
@@ -610,8 +610,15 @@
     G_GNUC_UNUSED QofCollection *m_col, *m_col2;
     QofIdType my_type = "my_type", my_type2 = "my_type2";
     guint param = (guint) g_test_rand_int();
-    gchar *msg1 = "qof_book_foreach_collection: assertion " _Q "book' failed";
-    gchar *msg2 = "qof_book_foreach_collection: assertion " _Q "cb' failed";
+/* GLib assertion messages which aren't filtered to make clang's output like gcc's */
+#ifdef __clang__
+#define _func "void qof_book_foreach_collection(const QofBook *, QofCollectionForeachCB, gpointer)"
+#else
+#define _func "qof_book_foreach_collection"
+#endif
+    gchar *msg1 = _func ": assertion " _Q "book' failed";
+    gchar *msg2 = _func ": assertion " _Q "cb' failed";
+#undef _func
     gchar *log_domain = "qof";
     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, hdlr;
     TestErrorStruct check1 = { loglevel, log_domain, msg1 };
@@ -634,7 +641,7 @@
     qof_book_foreach_collection( NULL, mock_foreach_collection, (gpointer)(&param) );
     g_assert( !col_struct.col1_called );
     g_assert( !col_struct.col2_called );
-    g_assert_cmpstr( test_struct.msg, == , "qof_book_foreach_collection: assertion " _Q "book' failed" );
+    g_assert_cmpstr( test_struct.msg, == , msg1);
     g_free( test_struct.msg );
 
     g_test_message( "Testing when cb is null" );
@@ -642,7 +649,7 @@
     qof_book_foreach_collection( fixture->book, NULL, (gpointer)(&param) );
     g_assert( !col_struct.col1_called );
     g_assert( !col_struct.col2_called );
-    g_assert_cmpstr( test_struct.msg, == , "qof_book_foreach_collection: assertion " _Q "cb' failed" );
+    g_assert_cmpstr( test_struct.msg, == , msg2);
     g_free( test_struct.msg );
     g_log_remove_handler (log_domain, hdlr);
     test_clear_error_list ();



More information about the gnucash-changes mailing list