blob: c6ffed7452481548e1146ae0d103f034e82f9e5e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
|