After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 647826 - API: gtester: Add g_test_fail()
API: gtester: Add g_test_fail()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-04-15 01:25 UTC by Benjamin Otte (Company)
Modified: 2011-04-18 15:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
API: gtester: Add g_test_fail() (3.98 KB, patch)
2011-04-15 01:25 UTC, Benjamin Otte (Company)
none Details | Review

Description Benjamin Otte (Company) 2011-04-15 01:25:15 UTC
This allows tests to fail in a nonfatal way and the test runner can
continue if invoked with -k.
Comment 1 Benjamin Otte (Company) 2011-04-15 01:25:18 UTC
Created attachment 185988 [details] [review]
API: gtester: Add g_test_fail()
Comment 2 Christian Dywan 2011-04-15 13:20:02 UTC
I like the idea of non-fatal failures, when I think of validating function output with multiple input values where it's useful to compare which of those failed and which didn't.

How does g_test_fail () play with g_assert_strcmp and friends? An example of how this should be used would be appreciated.
Comment 3 Benjamin Otte (Company) 2011-04-15 14:25:17 UTC
As pointed out on IRC, g_assert_strcmp() is one layer above this function. This is pretty much the nonfatal equivalent to abort(), which is the way how the assertions messages indicate fatal failures currently.

It would not be hard to add a nonfatal layer using the g_test_fail() if we wanted to do that. But that'd be a separate bug.

An example test function for this is http://git.gnome.org/browse/gtk+/tree/tests/css/parser/test-css-parser.c?h=http://git.gnome.org/browse/gtk+/commit/?h=parser&id=91d1d29d91ec35a4d9a5bfa0b70141e769a320fe#n165

The function takes a CSS file, parses it and then calls css_provider_to_string() to check that the parsed CSS matches a reference css file. This is a nice way to check that the parser's implementation of the CSS grammer and its error detection and recovery work as expected. Because a broken check is not fatal to or damaging to the integrity of the test-runner, it is fine to just indicate test failure and continue with the next test instead of restarting the whole test-running application.

Also, it improves performance by an order of 10, as we don't have to gtk_init() just to check a 100bytes css file.
Comment 4 Matthias Clasen 2011-04-16 11:58:56 UTC
Makes sense to me.
Comment 5 Benjamin Otte (Company) 2011-04-18 15:09:54 UTC
After fixing the patch to actually make the test runner fail (oops), I committed it to master.