News for hackers. Stuff that matters.
Re:MinUnit: a minimal unit testing framework for C by int_19h on Monday May 08, 2017 @09:25PM (#14297048)
This is obviously not an option for embedded stuff, but on many common platforms, it's actually easiest to unit-test C from Python. While you do need to write extra glue code (although ctypes are often "good enough" for tests, significantly reducing that amount), it's just so much easier to set things up in Python - i.e. generate inputs (especially strings!), set up files etc.
Re:MinUnit: a minimal unit testing framework for C by pagnol on Tuesday May 09, 2017 @04:38AM (#14298533)
Would you mind giving an example of how you would unit test a function?
Re:MinUnit: a minimal unit testing framework for C by int_19h on Tuesday May 09, 2017 @05:09PM (#14303838)
The same way you would unit test a Python function, except you invoke the actual C function using e.g. ctypes:

https://docs.python.org/3/library/ctypes.html

but your unit test is written in Python, including all the setup/teardown stuff and asserts. And you run it using the stock Python test runner (or some wrapper around that):

https://docs.python.org/3/library/unittest.html

(In theory, this all can be done even smoother if you use Cython, because that lets you interface with C more naturally than ctypes. I haven't tried that, though.)

Note that this all makes sense for C APIs, not C++ ones. With C++ APIs, as soon as classes etc come into the picture, and especially once you start dealing with STL and Boost data types, it becomes too difficult to invoke that stuff from Python. However, the implementation can be in any language - what matters is what the tested API looks like.

Re:MinUnit: a minimal unit testing framework for C by codebeaker on Tuesday May 09, 2017 @05:40AM (#14298707)
I'd be really interested to learn more about your technique too, sounds intriguing.