CMocka 2.0 Released: Enhancing Unit Testing in C

cmokca 2.0 released
cmokca 2.0 released

I am thrilled to announce the release of cmocka 2.0, a milestone for the cmocka project.

cmocka is a unit testing framework for C, designed to be simple, portable, and easy to use. It provides a straightforward API for writing and running tests, making it an excellent choice for developers who need to ensure the reliability and correctness of their C code.

A Brief History of cmocka

cmocka began its journey in 2011 as a successor to Google’s cmockery. I first tried to get in contact with the developers as several bugs which have been fixed started to bitrot in their bug track. I started to fix those issues first and then address many of its limitations while maintaining the philosophy of simplicity. Since then, it has grown to become a widely-used testing framework in the C ecosystem, powering test suites for numerous closed and open-source projects.

It’s important to note that cmocka is a spare-time project. As such, things sometimes move slower than I’d like, but I try to remain committed to deliver solid, reliable releases.

What’s New in 2.0?

This release represents a major modernization effort, bringing cmocka firmly into the “modern” C99 era while maintaining the simplicity and ease of use that users have come to expect.

One of the most significant changes in cmocka 2.0 is the migration to C99 standard integer types. The LargestIntegralType typedef has been replaced with intmax_t and uintmax_t from stdint.h, providing better type safety and portability across different platforms. Additionally, we’ve adopted the bool type where appropriate, making the code more expressive and self-documenting.

Using intmax_t and uintmax_t also allows to print better error messages. So you can now find e.g. assert_int_equal and assert_uint_equal.

cmocka 2.0 introduces a comprehensive set of type-specific assertion macros, including `assert_uint_equal()`, `assert_float_equal()`, and enhanced pointer assertions. The mocking system has also been significantly improved with type-specific macros like `will_return_int()` and `will_return_float()`. The same for parameter checking etc.

Modern Output Formats

The framework now supports TAP 14 (Test Anything Protocol) with YAML diagnostics, making it easier to integrate with modern CI/CD pipelines and test result analyzers. cmocka 2.0 also supports multiple simultaneous output formats, giving you flexibility in how you consume test results.

Build System Improvements

In addition to the existing CMake support, cmocka 2.0 now includes Meson build system integration, catering to projects using modern build tools.

API Stability

While cmocka 2.0 includes many improvements and changes, we’ve maintained API stability to ensure a smooth upgrade path for existing users. The ABI (Application Binary Interface) has changed, but this isn’t a concern for a unit testing library since tests are typically recompiled with each build. Your existing test code should continue to work with minimal or no modifications.

In case you find any issues you can report a bug here.

Thanks

I would like to thank all the contributors who’ve helped make this release possible, whether through code contributions, bug reports, documentation improvements, or simply using cmocka in their projects.

Get Started

You can download cmocka 2.0 from cmocka.org or install it through your distribution’s package manager. Full API documentation is available here. The complete changelog can be found here.

Happy testing!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *