How do I run unit tests using the GLib framework?

Viewed 2098

I'm trying to run simple unit tests for some C code I'm writing using GLib. I'm trying to do something like:

#include <math.h>
#include <stdio.h>

#include <glib.h>

static void 
test_stuff () 
{
  g_assert (1 == 1); //Say
}

int main (int argc, char **argv)
{
  g_test_init (&argc, &argv);
  g_test_add_func ("/TestTest", test_stuff);

  return g_test_run();
}

But when I compile (say to a binary called exec) and try to run this using gtester (or even running said binary directly), I get the following error:

me@laptop:tests$ gtester exec
TEST: exec... (pid=6503)

(process:6503): GLib-CRITICAL **: g_test_init: assertion `vararg1 == NULL' failed
FAIL: exec
Terminated

Is there something I'm missing, maybe variables I should pass as I run the tests?

1 Answers
Related