I tend to use it over others because it exists in a single header file, so it’s easy to add to existing projects without fighting my build system for too long.
Y’know – I was tempted to add a snarky “unless you need to be compatible with C89 <scoff>”. I will acknowledge that there are some (hopefully very very few) legit use cases where bool support is missing.
I’ve worked on a couple projects that needed C89 compatibility (mostly in embedded), and I begrudgingly keep greatest to -std=c89 just so that it’s always an option. There are some features that are only available when it’s built with >= C99 though.
For projects that are exactly C (not C++), I found check quite nice. It’s in C and has no C++ dependencies.
Here’s an example: https://github.com/vyos/ipaddrcheck/blob/current/tests/check_ipaddrcheck.c
Another one that’s focused on C that I’ve enjoyed for several years now is greatest.
https://github.com/silentbicycle/greatest
I tend to use it over others because it exists in a single header file, so it’s easy to add to existing projects without fighting my build system for too long.
Love greatest, it runs everywhere so you have no problems getting it to build on your CI.
Also used µnit sometimes, the reproducible random number generator can be great when a test fails.
That looks great, with a similar API to gtest. Thanks for the tip!
Thanks for sharing, this is a handy reference.
Aside: IMO logical expressions with
==
should bebool
and notint
.This depends on the C standard –
bool
isn’t in C89, so it can become a portability issue.Y’know – I was tempted to add a snarky “unless you need to be compatible with C89 <scoff>”. I will acknowledge that there are some (hopefully very very few) legit use cases where
bool
support is missing.Indeed, and I’m inclined to agree otherwise.
I’ve worked on a couple projects that needed C89 compatibility (mostly in embedded), and I begrudgingly keep greatest to
-std=c89
just so that it’s always an option. There are some features that are only available when it’s built with >= C99 though.Anyone have recommendations for other types of testing for C? Like property testing and mutation testing, etc.
For property-based testing, look at theft.