diff options
Diffstat (limited to 'tests/unit-tests-prep.sh')
-rwxr-xr-x | tests/unit-tests-prep.sh | 108 |
1 files changed, 80 insertions, 28 deletions
diff --git a/tests/unit-tests-prep.sh b/tests/unit-tests-prep.sh index 9f98c51e..a27e0195 100755 --- a/tests/unit-tests-prep.sh +++ b/tests/unit-tests-prep.sh @@ -1,53 +1,105 @@ -#!/usr/local/bin/bash +#!/bin/sh -e -# Auto generate single AllTests file for CuTest. -# Searches through all *.c files in the current directory. -# Prints to stdout. -# Author: Asim Jalis -# Date: 01/08/2003 +set -e -if test $# -eq 0 ; then FILES=*.c ; else FILES=$* ; fi +# -------------------------------------------------------------------- -echo ' +usage() +{ + echo "usage: unit-test-prep.sh -b base-name files.c ..." >&2 + exit 2 +} +header_top() +{ +cat << END /* This is auto-generated code. Edit at your own peril. */ -#include "CuTest.h" +#include "cu-test/CuTest.h" #include <stdio.h> +#include <gtk/gtk.h> -' - -cat $FILES | grep '^void unit_test_' | - sed -e 's/(.*$//' \ - -e 's/$/(CuTest*);/' \ - -e 's/^/extern /' +END +} -echo \ -' +header_bottom() +{ +cat << END +END +} -void RunAllTests(void) +source_top() +{ +cat << END +static void RunAllTests(void) { CuString *output = CuStringNew(); CuSuite* suite = CuSuiteNew(); -' -cat $FILES | grep '^void unit_test_' | - sed -e 's/^void //' \ - -e 's/(.*$//' \ - -e 's/^/ SUITE_ADD_TEST(suite, /' \ - -e 's/$/);/' +END +} -echo \ -' +source_bottom() +{ +cat << END CuSuiteRun(suite); CuSuiteSummary(suite, output); CuSuiteDetails(suite, output); printf("%s\\n", output->buffer); } -int main(int argc, char* argv) +int main(int argc, char* argv[]) { gtk_init(&argc, &argv); RunAllTests(); + return 0; +} +END } -' + +# -------------------------------------------------------------------- + +BASE=unit-test + +while [ $# -gt 0 ]; do + case "$1" in + -b) + BASE="$2" + shift + ;; + --) + shift + break + ;; + -*) + usage + ;; + *) + break + ;; + esac + shift +done + +# Must specify some files +if [ $# -eq 0 ]; then + usage +fi + +FILES=$* + +( + header_top + cat $FILES | grep '^void unit_test_' | sed -e 's/$/;/' + header_bottom +) > $BASE.h + +( + echo "#include \"$BASE.h\"" + source_top + cat $FILES | grep '^void unit_test_' | \ + sed -e 's/^void //' -e 's/(.*$//' \ + -e 's/^/ SUITE_ADD_TEST(suite, /' -e 's/$/);/' + source_bottom +) > $BASE.c + |