User: Password:
Subscribe / Log in / New account

On the importance of return codes

On the importance of return codes

Posted Dec 3, 2009 9:07 UTC (Thu) by michaeljt (subscriber, #39183)
Parent article: On the importance of return codes

> Worse yet, without some kind of comprehensive fault-injection framework, those error paths are difficult to test.
I was playing around with the idea of a simple script that could extract parts of a C(++) file and make simple changes based on something similar to Doxygen comments in order to unit test that sort of thing. That is, your script extracts the body code of the functions you want to unit test, glues on alternative header and footer code that you write in the doxygen comments, and replaces function calls where you want to test failure conditions with simple checks against a function parameter that you supply.


bool func_to_test()
/** @test_header bool my_test_func(void *malloc_result) */
/** @start_extracting_here */
... code ...
/** @replace_next_line_with my_global_pointer = malloc_result */
my_global_pointer = malloc(sizeof_struct);
return (my_global_pointer != NULL);
/** @stop_extracting_here */

/** @start_testing_code
* assert(my_test_func((void *)-1));
* assert(!my_test_func(NULL));
/** @end_testing_code */

Perhaps I will get round to finishing it in the next couple of weeks...

(Log in to post comments)

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds