1. 8
  1. 8

    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

    1. 7

      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.

      1. 5

        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.

        1. 2

          That looks great, with a similar API to gtest. Thanks for the tip!

      2. 2

        Thanks for sharing, this is a handy reference.

        Aside: IMO logical expressions with == should be bool and not int.

        1. 2

          This depends on the C standard – bool isn’t in C89, so it can become a portability issue.

          1. 1

            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.

            1. 2

              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.

        2. 1

          Anyone have recommendations for other types of testing for C? Like property testing and mutation testing, etc.

          1. 3

            For property-based testing, look at theft.