aboutsummaryrefslogtreecommitdiff
path: root/mkunit.sh
diff options
context:
space:
mode:
Diffstat (limited to 'mkunit.sh')
-rwxr-xr-xmkunit.sh34
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
3function mkfunc()
4{
5 echo "void $1() /**< expect ${2:-pass} */"
6}
7
8function 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
17sedbits=""
18init="#include \"bu/unitsuite.h\"\\\\n\\\\nclass Unit : public Bu::UnitSuite\\\\n{\\\\npublic:\\\\n\\\\nUnit()\\\\n{\\\\n\\\\tsetName(\"${1%.*}\");\\\\n"
19for 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'))"
22done
23
24init="${init}\\\\n}\\\\n\\\\nvirtual ~Unit() { }\\\\n\\\\n"
25
26sedbits="${sedbits}s@.*{=Init}@${init}@\n"
27
28temp=$(mktemp)
29echo -e "$sedbits" > $temp
30sed -f $temp $1 > $2
31echo -e "\n};\n\nint main( int argc, char *argv[] )\n{\n\treturn Unit().run( argc, argv );\n}\n" >> $2
32
33rm $temp
34