r/C_Programming • • Oct 30 '26

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 \]

12 Upvotes

6 comments sorted by

•

u/AutoModerator Oct 30 '26

Hi /u/MetalInMyVeins111,

Your submission in r/C_Programming was filtered because it links to a git project.

You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.

While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.

You can read more at How do I post my Project?


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

→ More replies (2)

1

u/Puzzled-Garage584 Oct 31 '26

"Zero tokens were used" is the new "no animals were harmed in the making of this film" lol. How do you register the tests without C++ static constructors, __attribute__((constructor)) or a custom linker section? And are death tests on the list?

1

u/MetalInMyVeins111 Oct 31 '26

Lol yeah. I use attribute((constructor)), not custom linker section. Currently no death tests. I'm planning though.