diff options
Diffstat (limited to 'tests/maketests.sh')
-rwxr-xr-x | tests/maketests.sh | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/maketests.sh b/tests/maketests.sh new file mode 100755 index 0000000..c6ffed7 --- /dev/null +++ b/tests/maketests.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +BASEDIR=$(dirname $(readlink -f $0)) + +function printhelp { + echo -e "usage:" + echo -e "-i, --input [FILE]" + echo -e "-o, --output [FILE]" + exit 1 +} + +function gen_code { + local CASES + CASES=$(sed -n '/#include.*\.c"/p' "$1" | cut -d'"' -f2 | grep -v '../src') + + for c in ${CASES}; do + local cc + cc=${c%.*} + printf " TCase * tc_%s = tcase_create(\"%s\");\n" ${cc} ${cc} + tests="" + tests=$(sed -n 's/START_TEST(\(.*\))/\1/p' "$BASEDIR/$c") + for t in ${tests}; do + printf " tcase_add_test(tc_%s, %s);\n" ${cc} ${t} + done + printf " suite_add_tcase(s, tc_%s);\n" ${cc} + done +} + +if [ $# -lt 1 ] +then + printhelp +fi + +while [[ $# -gt 0 ]] +do + key="$1" + case $key in + -i|--input) + INPUT="$2" + shift # past argument + shift # past value + ;; + -o|--output) + OUTPUT="$2" + shift # past argument + shift # past value + ;; + *) # unknown option + printhelp + ;; + esac +done + +if ! [ -f "$INPUT" ]; then + printhelp +fi + +sed "/maketests.sh begin/q" "$INPUT" > "$OUTPUT" +gen_code "$INPUT" >> "$OUTPUT" +sed -n -e '/maketests.sh end/,$p' "$INPUT" >> "$OUTPUT" +exit 0 |