X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Ftest.c;h=258517e76a19b13818d9b6eb0f79260197b78e4f;hp=b09f8471541e44676d929bba30342b9f78b4f8a4;hb=b111819a3d4c8dea01efe2c12ef21689ea0c21ed;hpb=379504a233e3e2cc85bca1e7b6d864f1395aec7c diff --git a/src/test.c b/src/test.c index b09f847..258517e 100644 --- a/src/test.c +++ b/src/test.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2009 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ @@ -27,7 +27,8 @@ static int test_failed = 0; static int test_todo = 0; static int test_verbose = 1; static const char *test_prog = 0; -static int log_tests = 0; +static int log_tests = 0; +static int test_stop = 0; static FILE *get_file(void) { @@ -74,11 +75,17 @@ void yaz_check_init1(int *argc_p, char ***argv_p) test_verbose = atoi(argv[i]); continue; } + else if (i < argc && !strcmp(suf, "stop")) + { + test_stop = 1; + continue; + } else if (!strcmp(suf, "help")) { - fprintf(stderr, + fprintf(stderr, "--test-help help\n" "--test-file fname output to fname\n" + "--test-stop stop at first failing test\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" @@ -95,7 +102,7 @@ void yaz_check_init1(int *argc_p, char ***argv_p) fprintf(stderr, "Use --test-help for more info\n"); exit(1); } - + } break; } @@ -110,7 +117,7 @@ void yaz_check_init1(int *argc_p, char ***argv_p) void yaz_check_init_log(const char *argv0) { char logfilename[2048]; - log_tests = 1; + log_tests = 1; sprintf(logfilename,"%s.log", progname(argv0) ); yaz_log_init_file(logfilename); yaz_log_trunc(); @@ -160,15 +167,15 @@ void yaz_check_eq1(int type, const char *file, int line, const char *left, const char *right, int lval, int rval) { char formstr[2048]; - - if (type == YAZ_TEST_TYPE_OK) + + if (type == YAZ_TEST_TYPE_OK) sprintf(formstr, "%.500s == %.500s ", left, right); else sprintf(formstr, "%.500s != %.500s\n %d != %d", left, right, lval,rval); yaz_check_print1(type, file, line, formstr); } -void yaz_check_print1(int type, const char *file, int line, +void yaz_check_print1(int type, const char *file, int line, const char *expr) { const char *msg = "unknown"; @@ -191,7 +198,7 @@ void yaz_check_print1(int type, const char *file, int line, } if (printit) { - fprintf(get_file(), "%s:%d %s: ", file, line, msg); + fprintf(get_file(), "%s:%d: %s: ", file, line, msg); fprintf(get_file(), "%s\n", expr); } if (log_tests) @@ -199,6 +206,10 @@ void yaz_check_print1(int type, const char *file, int line, yaz_log(YLOG_LOG, "%s:%d %s: ", file, line, msg); yaz_log(YLOG_LOG, "%s", expr); } + if ( type == YAZ_TEST_TYPE_FAIL && test_stop ) + { + exit(1); + } }