C tool for unit testing.

Giovanni Gherdovich g.gherdovich at gmail.com
Wed Jun 19 15:06:08 CDT 2013


Hello Iulian,

> So, I am new on testing tools in C, and until now  I
> managed to find some useful tools like 'Check'[1] and 'Google
> Test framework'[2].
>
> I would like to know your opinion about those tools, or if you
> know some others tools, and which one will fit with mercurial.
>
> I had tried to get some advice from C community, and there
> was just one guy that told me, he is using the 'Check' tool.
>
> [1]: http://check.sourceforge.net/
> [2]: http://code.google.com/p/googletest/
> [3]: http://stackoverflow.com/questions/65820/unit-testing-c-code

First off, I am as experienced as you on C.
Take what I say with a grain of salt; it's all things I've been told,
not first hand experience.

A few remarks:

(1) googletest is for C++, i.e. it doesn't compile with a C compiler.
(2) the framework you mention doesn't look bad, it's used by GStreamer
(3) If me myself had to make a choice in the next five minutes, I would
    go for the framework shipped with glib,
https://developer.gnome.org/glib/2.34/glib-Testing.html
    since... it's glib, c'mon. It's not gonna disappear anytime soon.
(4) Consider that the framework you choose will be, AFAICT, a dependency
    for hg like... forever. It better be good & with a long life ahead.
(5) Maybe too simplistic, but just for you to know: in the C standard
library
    there is a assert.h header file: `man 3 assert`
(6) I have been told about cUnit, http://cunit.sourceforge.net/index.html ,
    but I wouldn't go for it since it doesn't look very popular
    (what big project uses it?). Also, I've been told it doesn't support
    timeouts in tests

I have been spamming the whole freenode (and more) this afternoon, asking
to all big C projects I know of how they test their code.
I have asked to GCC, Wayland, Wine, Tor, Gnome, Bluez, Clutter,
ffmpeg, VLC, CPython, MariaDB, Postgres, Redis.

Apart from GCC (DejaGNU, not really for unit testing), they all
wrote their own framework. And among these, I'd go for
the glib one (Gnome & friends) with blind eyes.

= Personal advice =

Test the test framework !
Write down the kind of test you think you'll need to perform.
Then write dummy function on which perform such tests.

Then, *write those minimal tests* in your framework of choice.
Is it as expressive as you want it to be?

Like:
* I want to test return value of functions
* I want to test memory leaks
* I want to do tests that involve timeouts
* I want to do tests that involve a client and a server
* ...

then try to write those test on tiny dummy functions in
the framework you chose, try *all* the feature you need.
Soon better than later!

Cheers,
Giovanni
ggherdov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130619/76ba14b1/attachment.html>


More information about the Mercurial-devel mailing list