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 692125 - Support TAP as GTest output format
Support TAP as GTest output format
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks: 695688
 
 
Reported: 2013-01-20 08:58 UTC by Matthias Clasen
Modified: 2015-11-25 11:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
add start/stop suite log messages (2.62 KB, patch)
2013-01-20 08:58 UTC, Matthias Clasen
reviewed Details | Review
Add a GTestResult enum (2.71 KB, patch)
2013-01-20 08:58 UTC, Matthias Clasen
accepted-commit_now Details | Review
allow to mark tests as skipped or incomplete (4.75 KB, patch)
2013-01-20 08:59 UTC, Matthias Clasen
reviewed Details | Review
support tap (3.86 KB, patch)
2013-01-20 08:59 UTC, Matthias Clasen
accepted-commit_now Details | Review
optionally make assertions nonfatal (7.21 KB, patch)
2013-01-20 09:00 UTC, Matthias Clasen
reviewed Details | Review
add start/stop suite log messages (2.68 KB, patch)
2013-02-02 23:28 UTC, Matthias Clasen
reviewed Details | Review
update the protocol test (1.05 KB, patch)
2013-02-02 23:28 UTC, Matthias Clasen
reviewed Details | Review
add a GTestResult enum (2.88 KB, patch)
2013-02-02 23:29 UTC, Matthias Clasen
reviewed Details | Review
add functions to mark test as skipped or incomplete (4.48 KB, patch)
2013-02-02 23:29 UTC, Matthias Clasen
reviewed Details | Review
add a function to check test status (1.70 KB, patch)
2013-02-02 23:30 UTC, Matthias Clasen
reviewed Details | Review
support TAP as an output format (4.32 KB, patch)
2013-02-02 23:30 UTC, Matthias Clasen
reviewed Details | Review
make g_assert and g_assert_not_reached use the same entry point (2.02 KB, patch)
2013-02-02 23:31 UTC, Matthias Clasen
reviewed Details | Review
add g_assert_true (2.47 KB, patch)
2013-02-02 23:31 UTC, Matthias Clasen
none Details | Review
optionally make assertions nonfatal (5.58 KB, patch)
2013-02-02 23:32 UTC, Matthias Clasen
none Details | Review
update docs (4.98 KB, patch)
2013-02-02 23:32 UTC, Matthias Clasen
none Details | Review
start using tap (1.20 KB, patch)
2013-02-02 23:33 UTC, Matthias Clasen
none Details | Review

Description Matthias Clasen 2013-01-20 08:58:24 UTC
Created attachment 233932 [details] [review]
add start/stop suite log messages

Some initial patches towards producing TAP output, which would let us use other test harnesses than gtester.
Comment 1 Matthias Clasen 2013-01-20 08:58:48 UTC
Created attachment 233933 [details] [review]
Add a GTestResult enum
Comment 2 Matthias Clasen 2013-01-20 08:59:15 UTC
Created attachment 233934 [details] [review]
allow to mark tests as skipped or incomplete
Comment 3 Matthias Clasen 2013-01-20 08:59:37 UTC
Created attachment 233935 [details] [review]
support tap
Comment 4 Matthias Clasen 2013-01-20 09:00:01 UTC
Created attachment 233936 [details] [review]
optionally make assertions nonfatal
Comment 5 Colin Walters 2013-01-20 15:22:19 UTC
Review of attachment 233932 [details] [review]:

One question, otherwise looks good to me.

::: glib/gtestutils.h
@@ +297,3 @@
+  G_TEST_LOG_MESSAGE,           /* s:blurb */
+  G_TEST_START_SUITE,
+  G_TEST_STOP_SUITE

What's our compatibility story with respect to extending enums?  For this one it probably doesn't matter since I doubt anyone is doing a switch () on it.

But if we added a new one to say GFileType, that seems like it could break apps.
Comment 6 Colin Walters 2013-01-20 15:23:39 UTC
Review of attachment 233933 [details] [review]:

OK
Comment 7 Colin Walters 2013-01-20 15:25:39 UTC
Review of attachment 233934 [details] [review]:

Some convoluted code here, I'll trust you on this one; just two minor bits:

::: glib/gtestutils.c
@@ +1513,3 @@
+ * If not called from inside a test, this function does nothing.
+ *
+ * Since: 2.30

2.36

@@ +1536,3 @@
+ * If not called from inside a test, this function does nothing.
+ *
+ * Since: 2.30

2.36
Comment 8 Colin Walters 2013-01-20 15:26:56 UTC
Review of attachment 233935 [details] [review]:

Cool, I like TAP.
Comment 9 Emmanuele Bassi (:ebassi) 2013-01-20 15:29:02 UTC
(In reply to comment #5)

> What's our compatibility story with respect to extending enums?  For this one
> it probably doesn't matter since I doubt anyone is doing a switch () on it.
> 
> But if we added a new one to say GFileType, that seems like it could break
> apps.

we usually operate under the assumption that adding enumeration values is not an ABI break. to my recollection, and a quick check on the commit history, we've been doing that for years and years - with or without the explicit 'this enumeration may be extended at any later date' warning in the documentation blurb.

if you're switch()ing on an enumeration, you should have a 'default' rule to catch eventual new enumeration values; alternatively, use compiler warnings to catch that when rebuilding against a newer version of the libraries.
Comment 10 Colin Walters 2013-01-20 15:30:33 UTC
Review of attachment 233936 [details] [review]:

But this doesn't stop the test case from continuing execution, right?  I think porting tests is going to be a lot harder than just #define G_NONFATAL_ASSERT, because a lot of the GLib tests would immediately deference a NULL pointer or the like if they continued after an assertion.

Painful as it may be, I think the sane path forward is to add a new test signature that uses GError.
Comment 11 Emmanuele Bassi (:ebassi) 2013-01-20 15:34:57 UTC
Review of attachment 233935 [details] [review]:

looks cool to me, and I like TAP as well. :-)
Comment 12 Emmanuele Bassi (:ebassi) 2013-01-20 15:36:53 UTC
Review of attachment 233934 [details] [review]:

looks okay to me
Comment 13 Emmanuele Bassi (:ebassi) 2013-01-20 15:42:13 UTC
Review of attachment 233936 [details] [review]:

I agree with Colin: most of the tests written with GTest will end up in an inconsistent state after a failed g_assert(), and most likely segfault anyway. if the g_test_fail() immediately returned after the failure of a unit so that the test suite would continue running, it would be okay.

another one way to avoid the assertion would be to run each test unit in a separate process, and catch the assertion failure, though this would change a lot of the internals of GTest.
Comment 14 Colin Walters 2013-01-20 15:45:21 UTC
(In reply to comment #13)
> Review of attachment 233936 [details] [review]:
> 
> another one way to avoid the assertion would be to run each test unit in a
> separate process, and catch the assertion failure, though this would change a
> lot of the internals of GTest.

Yeah, I think this is what we need to do.
Comment 15 Matthias Clasen 2013-01-20 16:39:23 UTC
I think(In reply to comment #5)
> Review of attachment 233932 [details] [review]:
> 
> One question, otherwise looks good to me.
> 
> ::: glib/gtestutils.h
> @@ +297,3 @@
> +  G_TEST_LOG_MESSAGE,           /* s:blurb */
> +  G_TEST_START_SUITE,
> +  G_TEST_STOP_SUITE
> 
> What's our compatibility story with respect to extending enums?  For this one
> it probably doesn't matter since I doubt anyone is doing a switch () on it.

GTest is an unfortunate example of 'guts spilled out' api. This stuff is really all GTest internals that shouldn't have been in the header anywasy.

That being said, we can easily do without the start suite/end suite additions here, they are just used to generate some comments in tap output. But doing so was useful in that it make me find that g_test_add_vtable was totally busted.
Comment 16 Matthias Clasen 2013-01-20 16:55:21 UTC
(In reply to comment #13)

> I agree with Colin: most of the tests written with GTest will end up in an
> inconsistent state after a failed g_assert(), and most likely segfault anyway.
> if the g_test_fail() immediately returned after the failure of a unit so that
> the test suite would continue running, it would be okay.
> 
> another one way to avoid the assertion would be to run each test unit in a
> separate process, and catch the assertion failure, though this would change a
> lot of the internals of GTest.

So, that last patch was really mainly for discussion - thanks for providing that discussion !

I was aware of the fact that returning is needed, just a little scared of changing the semantics of asserts in that way. But maybe it is ok, since asserts are expected to be fatal. There's still the problem that adding a return will make asserts break the build in non-void functions...

One other idea I had was to tie the behaviour change to a runtime condition, say g_test_is_initialized().
Comment 17 Dan Winship 2013-01-20 17:12:18 UTC
(In reply to comment #10)
> But this doesn't stop the test case from continuing execution, right?  I think
> porting tests is going to be a lot harder than just #define G_NONFATAL_ASSERT,
> because a lot of the GLib tests would immediately deference a NULL pointer or
> the like if they continued after an assertion.

Sure, you can't just define G_NONFATAL_ASSERT in existing test programs and expect them to work. But you could write test programs that did work with it. The main reason I've never ported libsoup to use gtester is that the libsoup tests are all written to not crash on errors (where possible), and I like the fact that if something breaks, I can see *all* of the test failures rather than only the first one.

(In reply to comment #10)
> Painful as it may be, I think the sane path forward is to add a new test
> signature that uses GError.

(In reply to comment #13)
> another way to avoid the assertion would be to run each test unit in a
> separate process, and catch the assertion failure, though this would change a
> lot of the internals of GTest.

It's nice to be able to report multiple errors in a single test case too though. Eg, one gtest antipattern that pops up a lot is:

  success = my_op (arg, arg, &error);
  g_assert (success);
  g_assert_no_error (error);

If my_op fails, you're only going to see "assertion failed: success" rather than the much more useful message "got error 'file not found'". (So put the two assertions in the other order!) But anyway, if the test kept running after the first assertion, then it wouldn't matter what order you put them in. And lots of tests check multiple things that are semi-independent of each other. Eg, in mainloop.c there are lots of "check that source_a did what we expected, then check that source_b did what we expected, etc". It's useful to be able to still see if source b did the right thing even if source a failed. (Yes, in some cases the errors will be correlated, and you'll get redundant messages. But sometimes that's a useful data point too...)
Comment 18 Dan Winship 2013-01-20 17:13:29 UTC
Comment on attachment 233936 [details] [review]
optionally make assertions nonfatal

This needs to deal with g_warning(), etc, as well; currently they'd still be fatal errors, right?

Having a g_test_set_nonfatal_errors() or whatever might be better than having a #define
Comment 19 Matthias Clasen 2013-02-02 23:28:13 UTC
Created attachment 235079 [details] [review]
add start/stop suite log messages
Comment 20 Matthias Clasen 2013-02-02 23:28:43 UTC
Created attachment 235080 [details] [review]
update the protocol test
Comment 21 Matthias Clasen 2013-02-02 23:29:16 UTC
Created attachment 235081 [details] [review]
add a GTestResult enum
Comment 22 Matthias Clasen 2013-02-02 23:29:59 UTC
Created attachment 235082 [details] [review]
add functions to mark test as skipped or incomplete
Comment 23 Matthias Clasen 2013-02-02 23:30:29 UTC
Created attachment 235083 [details] [review]
add a function to check test status
Comment 24 Matthias Clasen 2013-02-02 23:30:58 UTC
Created attachment 235084 [details] [review]
support TAP as an output format
Comment 25 Matthias Clasen 2013-02-02 23:31:32 UTC
Created attachment 235085 [details] [review]
make g_assert and g_assert_not_reached use the same entry point
Comment 26 Matthias Clasen 2013-02-02 23:31:58 UTC
Created attachment 235086 [details] [review]
add g_assert_true
Comment 27 Matthias Clasen 2013-02-02 23:32:27 UTC
Created attachment 235087 [details] [review]
optionally make assertions nonfatal
Comment 28 Matthias Clasen 2013-02-02 23:32:54 UTC
Created attachment 235088 [details] [review]
update docs
Comment 29 Matthias Clasen 2013-02-02 23:33:20 UTC
Created attachment 235089 [details] [review]
start using tap
Comment 30 Matthias Clasen 2013-02-02 23:34:29 UTC
Here is another attempt; this time there is a g_test_set_nonfatal_assertions().
The last patch shows how converting glib tests to the automake tap driver and test harness looks.
Comment 31 Emmanuele Bassi (:ebassi) 2013-05-21 15:12:42 UTC
Review of attachment 235079 [details] [review]:

looks okay.
Comment 32 Emmanuele Bassi (:ebassi) 2013-05-21 15:13:21 UTC
Review of attachment 235080 [details] [review]:

dunno, maybe merge with the previous commit?

also, it would be nice to mention TAP.
Comment 33 Emmanuele Bassi (:ebassi) 2013-05-21 15:13:54 UTC
Review of attachment 235081 [details] [review]:

looks okay.
Comment 34 Emmanuele Bassi (:ebassi) 2013-05-21 15:15:02 UTC
Review of attachment 235082 [details] [review]:

looks okay.
Comment 35 Emmanuele Bassi (:ebassi) 2013-05-21 15:15:57 UTC
Review of attachment 235083 [details] [review]:

looks okay.
Comment 36 Emmanuele Bassi (:ebassi) 2013-05-21 15:30:54 UTC
Review of attachment 235084 [details] [review]:

looks good.
Comment 37 Emmanuele Bassi (:ebassi) 2013-05-21 15:32:09 UTC
Review of attachment 235085 [details] [review]:

looks good.
Comment 38 Emmanuele Bassi (:ebassi) 2013-05-21 15:34:24 UTC
Review of attachment 235087 [details] [review]:

::: glib/gtestutils.c
@@ +1644,3 @@
+g_test_set_nonfatal_assertions (void)
+{
+  g_return_if_fail (g_test_config_vars->test_initialized);

I would probably g_error(), here.
Comment 39 Emmanuele Bassi (:ebassi) 2013-05-21 15:39:42 UTC
Review of attachment 235086 [details] [review]:

prior art in other test suites is assert_true, assert_false, assert_null. should we add the others as well?
Comment 40 Matthias Clasen 2013-08-17 21:28:30 UTC
Pushed with the requested additions of g_assert_false, g_assert_null
Comment 41 Sven Neumann 2015-11-25 10:51:11 UTC
Did this ever make it into the master branch and a release? I don't see a --tap output option in recent versions of gtester and I can not see any of these commits in git master.
Comment 42 Emmanuele Bassi (:ebassi) 2015-11-25 11:34:31 UTC
Yes, you can use TAP with the GTest API — using the TAP support inside Automake, and without using the gtester helper (which is somewhat deprecated). See the glib-tap.mk file:

  https://git.gnome.org/browse/glib/tree/glib-tap.mk

I also wrote a quick guide on Stack Overflow on how to enable TAP for projects using GTest:

  http://stackoverflow.com/questions/19958861/how-to-properly-set-up-glib-testing-framework-with-autotools/19975406#19975406

Various projects have been migrated to using TAP instead of gtester; the main issue remaining is hitting an assertion inside a unit will terminate the whole suite, instead of skipping to the following unit; see bug 722648.