diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 25 | ||||
-rw-r--r-- | tests/check_parse.c | 4 | ||||
-rw-r--r-- | tests/foodtest.in | 50 | ||||
-rwxr-xr-x | tests/maketests.sh | 61 | ||||
-rw-r--r-- | tests/types.c | 39 | ||||
-rw-r--r-- | tests/util.c | 15 |
6 files changed, 186 insertions, 8 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 95bbaf5..d92a287 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,21 @@ -TESTS = check_parse -check_PROGRAMS = check_parse -check_parse_SOURCES = check_parse.c $(top_builddir)/src/parse.h -check_parse_CFLAGS = @CHECK_CFLAGS@ +# Setup TAP +LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ + $(top_srcdir)/build-aux/tap-driver.sh + +TESTS = foodtest + +EXTRA_DIST = maketests.sh \ + foodtest.in \ + types.c \ + util.c + +check_PROGRAMS = foodtest + +# foodtest_SOURCES = foodtest.c $(top_builddir)/src/parse.h +nodist_foodtest_SOURCES = foodtest.c +foodtest_CFLAGS = @CHECK_CFLAGS@ -lcheck + +CLEANFILES = foodtest.c + +foodtest.c: $(top_srcdir)/tests/foodtest.in $(top_srcdir)/tests/*.c + $(top_srcdir)/tests/maketests.sh -i $(top_srcdir)/tests/foodtest.in -o foodtest.c diff --git a/tests/check_parse.c b/tests/check_parse.c deleted file mode 100644 index f388ef8..0000000 --- a/tests/check_parse.c +++ /dev/null @@ -1,4 +0,0 @@ - -int main() { - return 0; -} diff --git a/tests/foodtest.in b/tests/foodtest.in new file mode 100644 index 0000000..484cfeb --- /dev/null +++ b/tests/foodtest.in @@ -0,0 +1,50 @@ +/* -*- mode: c -*- */ +#include <check.h> + +/* + * Source files check by this suite: + */ +#include "../src/types.c" +#include "../src/util.c" +/* + * Test suite based on check + * + * To add a new case simply create the <case>.c file + * in the tests/ directory and include it below + * Also add the new file to the EXTRA_DIST files in + * tests/Makefile.am + * + * To add a new test go to the appropriate case file + * and add it there + */ +#include "types.c" +#include "util.c" + +Suite * foodtest_suite(void) +{ + Suite *s; + + s = suite_create("foodtools tests"); + + /*** maketests.sh begin ***/ + /* everything in here will be replaced upon building */ + /* DO NOT delete the begin/end lines */ + /*** maketests.sh end ***/ + + return s; +} + +int main(void) +{ + int number_failed; + Suite *s; + SRunner *sr; + + s = foodtest_suite(); + sr = srunner_create(s); + srunner_set_tap(sr, "-"); + srunner_run_all(sr, CK_NORMAL); + number_failed = srunner_ntests_failed(sr); + srunner_free(sr); + return (number_failed == 0) ? 0 : CK_FAILURE; +} 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 diff --git a/tests/types.c b/tests/types.c new file mode 100644 index 0000000..9f08ac8 --- /dev/null +++ b/tests/types.c @@ -0,0 +1,39 @@ +/* -*- eval: (outline-minor-mode); outline-regexp: "START_TEST("; -*- */ + +static check_empty_recipe(recipe * r) { + ck_assert_int_eq(r->n, 1); + ck_assert_int_eq(r->in, 0); + ck_assert_int_eq(r->sn, 0); + ck_assert_int_eq(r->rn, 0); + + ck_assert_int_eq(r->sha1[0], '\0'); + + ck_assert_ptr_null(r->i); + ck_assert_ptr_null(r->s); + ck_assert_ptr_null(r->r); + ck_assert_ptr_null(r->filename); + ck_assert_ptr_null(r->path); + ck_assert_ptr_null(r->title); +} + +START_TEST(create_recipe) +{ + recipe * r = new_recipe(); + + check_empty_recipe(r); + + free_recipe(r); +} +END_TEST + +START_TEST(create_subrecipe) +{ + recipe * r = new_recipe(); + recipe * r_sub = new_recipe(); + new_subrecipe(r, r_sub); + + check_empty_recipe(r->r[r->rn -1]); + + free_recipe(r); +} +END_TEST diff --git a/tests/util.c b/tests/util.c new file mode 100644 index 0000000..6703abf --- /dev/null +++ b/tests/util.c @@ -0,0 +1,15 @@ +/* -*- eval: (outline-minor-mode); outline-regexp: "START_TEST("; -*- */ + +START_TEST(check_trim) +{ + char s1[10] = " test "; + char s2[10] = " test\n "; + char s3[10] = "\ttest\n "; + + trim(s1); trim(s2); trim(s3); + + ck_assert_str_eq(s1, "test"); + ck_assert_str_eq(s2, "test"); + ck_assert_str_eq(s3, "test"); +} +END_TEST |