News for hackers. Stuff that matters.
Re:The sad state of test frameworks by pg314 on Tuesday March 21, 2017 @02:26AM (#13920265)
Nothing. That's the way I usually test my C code.

It has the drawback that one failing test aborts the whole program. The error messages are not the most informative, but it does the job.

Re:The sad state of test frameworks by vortico on Tuesday March 21, 2017 @07:04AM (#13921166)
Although hacky,

    assert(test_foo() /* Checks the sanity of Foo */);
does the job for the error messages, and replacing abort() with a custom function like `void check(int condition, const char *format, ...);` can make it not abort the program on an error.

I prefer the regular assert() though because I want the build to fail by an aborting test program, and all I care is the line number of failure. Another benefit is that abort() will pause gdb in the exact place that it crashed, with the stack intact if you want to inspect it.

Re:The sad state of test frameworks by cormacrelf on Tuesday March 21, 2017 @08:05AM (#13921432)
You can also use the comma operator to document your assert()s, if you don't like using comments.

    assert(("test_foo() should be true", test_foo()));
https://en.wikipedia.org/wiki/Comma_operator#Asserts
Re:The sad state of test frameworks by gpderetta on Tuesday March 21, 2017 @08:10AM (#13921449)
I have used often and also seen in the wild the following form:

   assert(condition && "message");
Re:The sad state of test frameworks by klodolph on Tuesday March 21, 2017 @04:00AM (#13920517)
This is easy enough to solve on Unix... simply fork() before each test. Just make sure that the master is single-threaded or this won't work.
Re:The sad state of test frameworks by gpderetta on Tuesday March 21, 2017 @08:11AM (#13921453)
Also an option is to siglongjmp out of the abort signal handler.
Re:The sad state of test frameworks by codr4life on Tuesday March 21, 2017 @10:44AM (#13922585)
I've found it worthwhile to add a thin facade on top of assert to support out-of-band reporting of errors even if NDEBUG is disabled: https://github.com/codr4life/libc4/blob/master/src/c4/assert...