4 ms·
More sophisticated C unit testing libraries (libcheck, for example) use nice compiler features beyond ANSI C, like linker sets, in order to avoid error-prone du
by awda 13y ago
More sophisticated C unit testing libraries (libcheck, for example) use nice compiler features beyond ANSI C, like linker sets, in order to avoid error-prone duplicating like you see in these examples.
While that may not work in some environments that don't support these extensions, I'm having trouble imagining ones that support C stdio but do not support linker sets.
- silentbicycle 13y agoI (the author) have been doing a lot of embedded development lately, and in those cases you really can't assume very much beyond core ANSI C features. That's also why greatest doesn't do any dynamic allocation, at all. There's a relatively small struct for the current testing progress, and everything else can easily run out of ROM. My primary goal with greatest is to assume as little as possible, and avoid imposing any additional constraints on projects just because people want to test them. I also want the implementation to be very transparent -- it's just a 600-ish line header file, carefully documented. It's a major pet peeve of mine when I have to work around features that try to automatically be helpful, but have edge cases that break down in opaque ways. (Build systems tend to be particularly bad in that way.) Also, I'm beyond shocked that the name wasn't already taken. ;) One of my upcoming tasks is making stdio optional in greatest, because printf doesn't do you a whole lot of good if you're running it on an Arduino or something, but in those contexts automated testing is especially valuable.
- meekrosoft 13y agoCool, I really like this! I wrote a popular C function faking framework in a single header file for exactly the same reasons: all bets are off in embedded targets. https://github.com/meekrosoft/fff https://github.com/meekrosoft/fff The test C test framework in the project is 4 lines long, but does require the standard library. https://github.com/meekrosoft/fff/blob/master/test/c_test_framework.h https://github.com/meekrosoft/fff/blob/master/test/c_test_fr...
- silentbicycle 13y agofff looks cool, too. Thanks! I'll check it out. :) I've tended to use CMock (https://github.com/ThrowTheSwitch/CMock https://github.com/ThrowTheSwitch/CMock) for mocking, though it depends on some Ruby-based tooling. The last time I looked into replacing CMock I wound up hip-deep in the binutils. (It was fun when I stopped getting google results from StackOverflow and started getting them from Phrack, though. ;) )
- justinmk 13y agoDid you try cmocka? http://cmocka.org/ http://cmocka.org/ It was the most featureful that I found when I was looking last year.
- silentbicycle 13y agoI have not, but I'll check it out, thanks.