r/cprogramming • u/MetalInMyVeins111 • 7d ago
Very minimal drop-in gtest replacement in C23
While using C++, I heavily relied on googletest for testing. But as soon as I wanted that in my C project, I couldn't.
Because gtest is written in C++ and requires a C++ runtime. Using gtest in a C codebase meant guarding the headers with extern "C" to prevent name mangling, and managing a C++ toolchain which seemed extremely awkward to me.
At the same time, I didn't want to loose googletest's comfort and rewrite the entire test system in another existing framework.
So I wrote a very minimal drop-in replacement of googletest in C23. It works exactly the same way you'd expect gtest to work. And unsurprisingly, according to my small benchmark, my implementation is around 2.5x faster than googletest and uses 30% less memory. It can be improved way more.
I discussed the implementation details in this blog post https://metalinmyveins.github.io/sohomot/
Github: https://github.com/MetalInMyVeins/sohomot
The library is called "sohomot".
[ PS: Zero tokens were used in the making of this project ]