Is CATCH suitable for plain C projects?

120 views
Skip to first unread message

Jamie Bullock

unread,
Nov 8, 2014, 2:33:33 PM11/8/14
to catch...@googlegroups.com

Hi,

I'm currently evaluating unit testing frameworks for use in a plain C project (ANSI C99).

CATCH looks like a really nicely designed framework, but can you tell me if there are any caveats using it with plain C? 

It says in the GitHub README "C++, Objective-C (and maybe C)"

Are there any known (or suspected) issues, or is just that it hasn't been tested widely with C code?

Thanks,

Jamie

Ross Bencina

unread,
Nov 8, 2014, 7:15:16 PM11/8/14
to catch...@googlegroups.com
On 9/11/2014 6:33 AM, Jamie Bullock wrote:
> Are there any known (or suspected) issues, or is just that it hasn't
> been tested widely with C code?

Hi Jamie,

Just speculating (I only use CATCH with C++) but since CATCH is a
header-only C++ library, that means that your test cases will need to be
C++ files. There's no problem calling your ANSI C code from C++ of
course, so it should work.

I guess it depends on whether you're happy for your test cases to be
written in C++. That might be a problem if you're writing embedded code
on a platform without a C++ compiler, or if the interface to your C code
uses some incompatible C-ism (if such a thing exists).

Another thing is your test executables will need to be linked with the
C++ runtime. I can imagine this might be a subtle problem for some
low-level edge-case scenarios, but in general it shouldn't be a problem.

Cheers,

Ross.

Phil Nash

unread,
Nov 9, 2014, 3:20:54 PM11/9/14
to catch...@googlegroups.com
Yeah, everything Ross says is basically right (thanks Ross).
There are some incompatibilities with pure C due to how the languages have diverged in some minor ways. You can go a long time without hitting these, but I obviously can't guarantee you won't (and some have - which is what prompted me to qualify with the "maybe").

Jens Winslow

unread,
Dec 17, 2014, 11:36:22 AM12/17/14
to catch...@googlegroups.com
I have used it to test some C code without problems and it did fine (compiler / platform need to support C/C++ for tests, but code tested was plain C).
Reply all
Reply to author
Forward
0 new messages