From 16538abf8d1231279133508ba15376145b818518 Mon Sep 17 00:00:00 2001 From: gramanas Date: Tue, 10 May 2022 21:12:33 +0300 Subject: autotools and check testign suite --- tests/maketests.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 tests/maketests.sh (limited to 'tests/maketests.sh') 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 -- cgit v1.2.3