diff options
Diffstat (limited to 'mkunit.sh')
-rwxr-xr-x | mkunit.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mkunit.sh b/mkunit.sh new file mode 100755 index 0000000..867d6df --- /dev/null +++ b/mkunit.sh | |||
@@ -0,0 +1,34 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | function mkfunc() | ||
4 | { | ||
5 | echo "void $1() /**< expect ${2:-pass} */" | ||
6 | } | ||
7 | |||
8 | function mkadd() | ||
9 | { | ||
10 | ex="expectPass" | ||
11 | if [ "$2" == "fail" ]; then | ||
12 | ex="expectFail" | ||
13 | fi | ||
14 | echo "\\\\tadd( static_cast<Bu::UnitSuite::Test>(\\&Unit::$1), \"$1\", Bu::UnitSuite::${ex} );\\\\n" | ||
15 | } | ||
16 | |||
17 | sedbits="" | ||
18 | init="#include \"bu/unitsuite.h\"\\\\n\\\\nclass Unit : public Bu::UnitSuite\\\\n{\\\\npublic:\\\\n\\\\nUnit()\\\\n{\\\\n\\\\tsetName(\"${1%.*}\");\\\\n" | ||
19 | for i in $(grep {% "$1"); do | ||
20 | sedbits="${sedbits}s@${i}@$(mkfunc $(echo $i | sed -e 's/.*{%\(.*\)}/\1/' -e 's/:/ /g'))@\n" | ||
21 | init="${init}$(mkadd $(echo $i | sed -e 's/.*{%\(.*\)}/\1/' -e 's/:/ /g'))" | ||
22 | done | ||
23 | |||
24 | init="${init}\\\\n}\\\\n\\\\nvirtual ~Unit() { }\\\\n\\\\n" | ||
25 | |||
26 | sedbits="${sedbits}s@.*{=Init}@${init}@\n" | ||
27 | |||
28 | temp=$(mktemp) | ||
29 | echo -e "$sedbits" > $temp | ||
30 | sed -f $temp $1 > $2 | ||
31 | echo -e "\n};\n\nint main( int argc, char *argv[] )\n{\n\treturn Unit().run( argc, argv );\n}\n" >> $2 | ||
32 | |||
33 | rm $temp | ||
34 | |||