#!/bin/bash # This file is part of mutest, a micro testing framework for C. # # mutest is under the BOLA license, please see the LICENSE file or visit # http://blitiri.com.ar/p/bola/ # # This is a simple script to generate a C file that runs all the test cases # present in .o files passed as arguments. # # Please, read the README file for more details. # the trick here is getting all the test cases present in an object file using # nm. All the tests must take and return void, start with "mutest_" and, of # course, should not be static, which leads to a small limitation: all test # cases must have unique names, even across test suites. # the first argument should be mutest.h mutest_h="$1" shift echo "#include \"$mutest_h\"" echo "void mu_run_suites() {" echo for file in "$@" do suite="`basename "$file" .o | sed 's/\"/\\\\\"/g'`" echo -e '\tmutest_suite_name = "'"$suite"'";' echo -e '\tmu_print(MU_SUITE, "\\nRunning suite \"'"$suite"'\"\\n");' for symbol in `nm -p "$file" \ | egrep '^[[:xdigit:]]{8} T mu_test_\w+$' \ | cut -c12-` do echo -e "\tmu_run_case($symbol);" done echo -e "\tif (mutest_suite_failed) ++mutest_failed_suites;" echo -e "\telse ++mutest_passed_suites;" echo -e "\tmutest_suite_failed = 0;" echo done echo "}"