3 # This file is part of mutest, a simple micro unit testing framework for C.
5 # mutest was written by Leandro Lucarella <llucax@gmail.com> and is released
6 # under the BOLA license, please see the LICENSE file or visit:
7 # http://blitiri.com.ar/p/bola/
9 # This is a simple script to generate a C file that runs all the test suites
10 # present in .o files passed as arguments.
12 # Please, read the README file for more details.
16 # the trick here is getting all the test cases present in an object file using
17 # nm. All the tests must take and return void, start with "mutest_" and, of
18 # course, should not be static, which leads to a small limitation: all test
19 # cases must have unique names, even across test suites.
21 # the first argument should be mutest.h
24 echo "Too few arguments" >&2
25 echo "Usage: $0 mutest_h_location [object files...]" >&2
30 echo "#include \"$mutest_h\""
31 echo "void mu_run_suites() {"
35 pr_file=`echo "$file" | sed 's/\"/\\\\\"/g'`
36 suite=`basename "$file" .o | sed 's/\"/\\\\\"/g'`
37 symbols=`nm "$file" | egrep '^[[:xdigit:]]{8} T mu_\w+$' | cut -c12-`
38 tests=`echo "$symbols" | egrep '^mu_test'`
39 inits=`echo "$symbols" | egrep '^mu_init'`
40 terms=`echo "$symbols" | egrep '^mu_term'`
42 echo -e '\t\tmutest_suite_name = "'"$suite"'";'
43 echo -e '\t\tmu_print(MU_SUITE, "\\nRunning suite '"'$suite'"'\\n");'
46 echo -e "\\t\\tmu_run_init($init);"
48 for testcase in $tests
50 echo -e "\t\tmu_run_case($testcase);"
54 echo -e "\t\tmu_run_term($term);"
56 echo -e "\t\tif (mutest_suite_failed) ++mutest_failed_suites;"
57 echo -e "\t\telse ++mutest_passed_suites;"
58 echo -e "\t\tmutest_suite_failed = 0;"
59 echo -e '\t} while (0);'