X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftest.c;h=967b53b2a28cb99305375291f3cc5a13f40c7fe3;hb=06ae818deffa84ec4bc1308051ef411845dd4ce5;hp=0dc8bdff86617805d9de7903ac47dc2971e2ecc2;hpb=be1157fee3451c37508c9ec3b4b4b8603a646c0b;p=yaz-moved-to-github.git diff --git a/src/test.c b/src/test.c index 0dc8bdf..967b53b 100644 --- a/src/test.c +++ b/src/test.c @@ -2,20 +2,41 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: test.c,v 1.2 2006-01-27 19:01:56 adam Exp $ + * $Id: test.c,v 1.3 2006-01-29 21:59:13 adam Exp $ */ #if HAVE_CONFIG_H #include #endif +#include #include #include #include -static FILE *test_fout = 0; /* can't init this to stderr on some systems */ -static int test_number = 0; -static int test_verbose = 0; +static FILE *test_fout = 0; /* can't use '= stdout' on some systems */ +static int test_total = 0; +static int test_failed = 0; +static int test_verbose = 1; +static char *test_prog = 0; + +static FILE *get_file() +{ + if (test_fout) + return test_fout; + return stdout; +} + +static char *progname(char *argv0) +{ + char *cp = strrchr(argv0, '/'); + if (cp) + return cp+1; + cp = strrchr(argv0, '\\'); + if (cp) + return cp+1; + return argv0; +} void yaz_check_init1(int *argc_p, char ***argv_p) { @@ -23,6 +44,8 @@ void yaz_check_init1(int *argc_p, char ***argv_p) int argc = *argc_p; char **argv = *argv_p; + test_prog = progname(argv[0]); + for (i = 1; i= 7 && !memcmp(argv[i], "--test-", 7)) @@ -46,8 +69,13 @@ void yaz_check_init1(int *argc_p, char ***argv_p) { fprintf(stderr, "--test-help help\n" - "--test-verbose level verbose; 0=quiet; 1=normal; 2=more\n" - "--test-file fname output to fname\n"); + "--test-file fname output to fname\n" + "--test-verbose level verbose level\n" + " 0=Quiet. Only exit code tells what's wrong\n" + " 1=Report+Summary only if tests fail.\n" + " 2=Report failures. Print summary always\n" + " 3=Report + summary always\n" + ); exit(0); } else @@ -66,29 +94,50 @@ void yaz_check_init1(int *argc_p, char ***argv_p) --i; *argc_p -= i; *argv_p += i; - if (!test_fout) - test_fout = stdout; /* by default, set output to this */ +} + +void yaz_check_term1(void) +{ + /* summary */ + if (test_failed) + { + if (test_verbose >= 1) + fprintf(get_file(), "%d out of %d tests failed for program %s\n", + test_failed, test_total, test_prog); + } + else + { + if (test_verbose >= 2) + fprintf(get_file(), "%d tests passed for program %s\n", + test_total, test_prog); + } + if (test_fout) + fclose(test_fout); + if (test_failed) + exit(1); + exit(0); } void yaz_check_print1(int type, const char *file, int line, const char *expr) { const char *msg = "unknown"; - test_number++; + test_total++; switch(type) { case YAZ_TEST_TYPE_FAIL: + test_failed++; msg = "failed"; if (test_verbose < 1) return; break; case YAZ_TEST_TYPE_OK: msg = "OK"; - if (test_verbose < 2) + if (test_verbose < 3) return; break; } - fprintf(test_fout, "%s:%d %s: %s\n", file, line, msg, expr); + fprintf(get_file(), "%s:%d %s: %s\n", file, line, msg, expr); }