Re: RFC: GLib testing framework

On Tue, 6 Nov 2007, Matthias Clasen wrote:

On 11/1/07, Tim Janik <timj imendio com> wrote:

One thing I find pretty useful, that has not been mentioned so far (or
I missed it) is regression tests for bugs. For these it is very useful
to have some standardized way to refer to the bug they are testing.

people can use any naming scheme they want, there's no dictate for that in
the framework. e.g you could start to label your tests like this:

  g_test_add_func ("/gtk/bug/4711", test_rand1);
  g_test_add_func ("/gtk/bug/4712", test_assertions);
  g_test_add_func ("/gtk/bug/1313", test_timer);

or stick to:

  g_test_add_func ("/random-generator/rand-1", test_rand1);
  g_test_add_func ("/misc/assertions", test_assertions);
  g_test_add_func ("/misc/timer", test_timer);

- we provide an extended set of assertions for strings, ints and floats
   that allow printing of assertion arguments upon failures to reduce
   the need for debugging:
     g_assert_cmpfloat (arg1, cmpop, arg2);
     g_assert_cmpint   (arg1, cmpop, arg2);
     g_assert_cmpstr   (arg1, cmpop, arg2);
   used like:
     g_assert_cmpstr ("foo", !=, "faa");
     g_assert_cmpfloat (3.3, <, epsilon);
   g_assert() is still available of course, but using the above variants,
   assertion messages can be more elaborate, e.g.:
     ** testing.c:test_assertions(): assertion failed '(3.3 < epsilon)': (3.3 < 0.5)

This syntax strikes me as not particularly elegant and a pretty severe
clash with
C syntax. I don't think I can get myself to insert random commas into
expressions like that.

How about this instead ?

g_assert_with_message ("foo not smaller than bar", foo > bar)

nobody has to use this syntax. you can stick to the ever simple:
  g_assert (foo > bar);

however if you want the value of 'foo' and 'bar' be printed out, instead
of just the value of (foo > bar) which would be 0 or 1, then there are
no other means than using something simialr to:
  g_assert_cmpfloat (foo, >, bar);

i've checked in Sven's and my code into a git-svn mirror of glib on so you can browse the recent changes here:;a=shortlog;h=gtester

e.g. todays latest version of the testing examples is here:;a=blob;f=glib/tests/testing.c;hb=9c8ae8c0097b8f7c098970e87bf413cd9c4f6a22

and the latest API here:;a=blob;f=glib/gtestframework.h;hb=9c8ae8c0097b8f7c098970e87bf413cd9c4f6a22



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]