GNOME Bugzilla – Bug 52772
Proposal: g_friendly_assert (g_assert_with_message)
Last modified: 2011-02-18 16:14:11 UTC
A version of g_assert() which, along with the expr, takes a string which is printed along with the assert. Essentially a nicer version of: #define g_friendly_assert(expr,str) g_assert(expr && str) Asserts are different than g_warning()'s as assert's by definition are not complied into release binaries (for speed/size reasons). As glib provides many creature comforts, g_friendly_assert (or whatever the proposed name would be) would definately be welcome.
To make this useful, it would have to be at least g_assert_msg (expr, fmt, ...); so that you can write: g_assert_msg(x == 5, "expected 5, but got %d", x);
Created attachment 38578 [details] [review] New API g_assert_msg(expr, format...) The appended patch implements this API. On failed assertions, it produces the following output: ** ERROR **: file test.c: line 6 (main): This is working correctly. aborting... The gcc code is tested, but since I have no non-GNU compiler available someone else still needs to test that part of the patch.
Created attachment 38633 [details] [review] Fixed formatting I have now tested the patch with both, gcc and non-gcc and it works fine. Anyway, I have appended a patch that fixes the previously broken formatting.
This looks interesting : any reason why it is stuck ?
We added a bunch of message-enhanced assert macros with the new test framework, so I think this can be closed.