summaryrefslogtreecommitdiffstats
path: root/tests/maketests.sh
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2022-05-10 21:12:33 +0300
committergramanas <anastasis.gramm2@gmail.com>2022-05-10 21:12:33 +0300
commit16538abf8d1231279133508ba15376145b818518 (patch)
treee19079645f87163f674faa333044330c37374ea9 /tests/maketests.sh
parente739c5dccc0faf13cbddacd1950e203305aa4bab (diff)
downloadfoodtools-16538abf8d1231279133508ba15376145b818518.tar.gz
foodtools-16538abf8d1231279133508ba15376145b818518.tar.bz2
foodtools-16538abf8d1231279133508ba15376145b818518.zip
autotools and check testign suite
Diffstat (limited to 'tests/maketests.sh')
-rwxr-xr-xtests/maketests.sh61
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