From cf73759d92858885e4e71f6fc85f6d4478593958 Mon Sep 17 00:00:00 2001 From: Peter Verthez Date: Sat, 26 Oct 2002 16:04:01 +0000 Subject: [PATCH] Restructure output from tests. --- t/src/gomtest.c | 15 ++++++++++++++- t/src/output.c | 12 +++++++----- t/src/output.h | 4 ++-- t/src/standalone.c | 15 ++++++++++++++- t/src/test_gom | 36 ++++++++++++++++++++++++++++++++---- t/src/test_script | 36 ++++++++++++++++++++++++++++++++---- t/src/test_update | 36 ++++++++++++++++++++++++++++++++---- t/src/update.c | 15 ++++++++++++++- 8 files changed, 147 insertions(+), 22 deletions(-) diff --git a/t/src/gomtest.c b/t/src/gomtest.c index ad165fb..942f703 100644 --- a/t/src/gomtest.c +++ b/t/src/gomtest.c @@ -41,6 +41,7 @@ void show_help () printf(" -dg Debug setting: only libgedcom debug messages\n"); printf(" -da Debug setting: libgedcom + yacc debug messages\n"); printf(" -q No output to standard output\n"); + printf(" -o File to generate output to (def. testgedcom.out)\n"); } void gedcom_message_handler(Gedcom_msg_type type, char *msg) @@ -54,6 +55,7 @@ int main(int argc, char* argv[]) int compat_enabled = 1; int debug_level = 0; int result = 0; + char* outfilename = NULL; char* file_name = NULL; if (argc > 1) { @@ -78,6 +80,17 @@ int main(int argc, char* argv[]) else if (!strncmp(argv[i], "-q", 3)) { output_set_quiet(1); } + else if (!strncmp(argv[i], "-o", 3)) { + i++; + if (i < argc) { + outfilename = argv[i]; + } + else { + printf ("Missing output file name\n"); + show_help(); + exit(1); + } + } else if (strncmp(argv[i], "-", 1)) { file_name = argv[i]; break; @@ -103,7 +116,7 @@ int main(int argc, char* argv[]) gedcom_set_error_handling(mech); gedcom_set_message_handler(gedcom_message_handler); - output_open(); + output_open(outfilename); output(0, "\n=== Parsing file %s\n", file_name); result = gom_parse_file(file_name); if (result == 0) { diff --git a/t/src/output.c b/t/src/output.c index d2922cb..c31c162 100644 --- a/t/src/output.c +++ b/t/src/output.c @@ -25,11 +25,11 @@ #include #include -#define OUTFILE "testgedcom.out" +#define OUTFILE "check.out" FILE* outfile = NULL; int quiet = 0; -void output(int to_stdout_too, char* format, ...) +void output(int to_stdout_too, const char* format, ...) { va_list ap; va_start(ap, format); @@ -47,11 +47,13 @@ void output_set_quiet(int q) quiet = q; } -void output_open() +void output_open(const char *outfilename) { - outfile = fopen(OUTFILE, "a"); + if (!outfilename) + outfilename = OUTFILE; + outfile = fopen(outfilename, "a"); if (!outfile) { - printf("Could not open %s for appending\n", OUTFILE); + printf("Could not open %s for appending\n", outfilename); } } diff --git a/t/src/output.h b/t/src/output.h index 154ccf3..25ae507 100644 --- a/t/src/output.h +++ b/t/src/output.h @@ -27,9 +27,9 @@ #include #include -void output(int to_stdout_too, char* format, ...); +void output(int to_stdout_too, const char* format, ...); void output_set_quiet(int q); -void output_open(); +void output_open(const char *outfilename); void output_close(); #endif /* __OUTPUT_H */ diff --git a/t/src/standalone.c b/t/src/standalone.c index 44483e7..4b21ddc 100644 --- a/t/src/standalone.c +++ b/t/src/standalone.c @@ -50,6 +50,7 @@ void show_help () printf(" -3 Run the test parse 3 times instead of once\n"); printf(" -b Parse a bogus file before parsing the main file\n"); printf(" -q No output to standard output\n"); + printf(" -o File to generate output to (def. testgedcom.out)\n"); } Gedcom_ctxt header_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag, @@ -227,6 +228,7 @@ int main(int argc, char* argv[]) int run_times = 1; int bogus = 0; int result = 0; + char* outfilename = NULL; char* file_name = NULL; if (argc > 1) { @@ -260,6 +262,17 @@ int main(int argc, char* argv[]) else if (!strncmp(argv[i], "-q", 3)) { output_set_quiet(1); } + else if (!strncmp(argv[i], "-o", 3)) { + i++; + if (i < argc) { + outfilename = argv[i]; + } + else { + printf ("Missing output file name\n"); + show_help(); + exit(1); + } + } else if (strncmp(argv[i], "-", 1)) { file_name = argv[i]; break; @@ -287,7 +300,7 @@ int main(int argc, char* argv[]) gedcom_set_default_callback(default_cb); subscribe_callbacks(); - output_open(); + output_open(outfilename); if (bogus) { output(0, "\n=== Parsing bogus file %s\n", BOGUS_FILE_NAME); gedcom_parse_file(BOGUS_FILE_NAME); diff --git a/t/src/test_gom b/t/src/test_gom index 0dbcd62..108f498 100755 --- a/t/src/test_gom +++ b/t/src/test_gom @@ -17,7 +17,12 @@ do done file=$1 -expected_result=$2 +test_name=$2 +expected_result=$3 +if [ -z "$test_name" ] +then + test_name=check +fi if [ -z "$expected_result" ] then expected_result=0 @@ -34,6 +39,11 @@ else options="$options $extra_options" fi +outfile=$test_name.out +logfile=check.out +reffile=$srcdir/output/$test_name.ref +options="$options -o $outfile" + builddir=`pwd` ltcmd="$builddir/../libtool --mode=execute -dlopen $builddir/../gedcom/libgedcom.la -dlopen $builddir/../gom/libgedcom_gom.la" GCONV_PATH=.:$GCONV_PATH @@ -42,6 +52,8 @@ ln -s $srcdir/../data/gedcom.enc . ln -s $builddir/../iconv/glibc/.libs/ANSI_Z39.47.so . ln -s $srcdir/../iconv/glibc/gconv-modules . rm -f core +echo "======================================================">> $logfile +echo "Performing test '$test_name'" >> $logfile if [ "$GOM_DMALLOC_TEST" = "" ] then $ltcmd $GEDCOM_TESTENV $builddir/src/gomtest $options $testfile @@ -55,9 +67,25 @@ result=$? rm gedcom.enc rm ANSI_Z39.47.so rm gconv-modules -if [ "$result" -eq "$expected_result" -a ! -r core ] + +echo "Result is $result (expected: $expected_result)" >> $logfile +if [ "$result" -ne "$expected_result" ] then - exit 0 -else exit 1 +else + if [ -r core ] + then + echo "Core file generated!" >> $logfile + exit 1 + else + if diff $outfile $reffile >/dev/null 2>>$logfile + then + echo "Output agrees with reference output" >> $logfile + rm $outfile + exit 0 + else + echo "Differences with reference output detected!" >> $logfile + exit 1 + fi + fi fi diff --git a/t/src/test_script b/t/src/test_script index ebcda7b..3a1cf8e 100755 --- a/t/src/test_script +++ b/t/src/test_script @@ -15,7 +15,12 @@ do done file=$1 -expected_result=$2 +test_name=$2 +expected_result=$3 +if [ -z "$test_name" ] +then + test_name=check +fi if [ -z "$expected_result" ] then expected_result=0 @@ -32,6 +37,11 @@ else options="$options $extra_options" fi +outfile=$test_name.out +logfile=check.out +reffile=$srcdir/output/$test_name.ref +options="$options -o $outfile" + builddir=`pwd` ltcmd="$builddir/../libtool --mode=execute -dlopen $builddir/../gedcom/libgedcom.la" GCONV_PATH=.:$GCONV_PATH @@ -40,14 +50,32 @@ ln -s $srcdir/../data/gedcom.enc . ln -s $builddir/../iconv/glibc/.libs/ANSI_Z39.47.so . ln -s $srcdir/../iconv/glibc/gconv-modules . rm -f core +echo "======================================================">> $logfile +echo "Performing test '$test_name'" >> $logfile $ltcmd $GEDCOM_TESTENV $builddir/src/testgedcom $options $testfile result=$? rm gedcom.enc rm ANSI_Z39.47.so rm gconv-modules -if [ "$result" -eq "$expected_result" -a ! -r core ] + +echo "Result is $result (expected: $expected_result)" >> $logfile +if [ "$result" -ne "$expected_result" ] then - exit 0 -else exit 1 +else + if [ -r core ] + then + echo "Core file generated!" >> $logfile + exit 1 + else + if diff $outfile $reffile >/dev/null 2>>$logfile + then + echo "Output agrees with reference output" >> $logfile + rm $outfile + exit 0 + else + echo "Differences with reference output detected!" >> $logfile + exit 1 + fi + fi fi diff --git a/t/src/test_update b/t/src/test_update index cbe0c33..127b0bc 100755 --- a/t/src/test_update +++ b/t/src/test_update @@ -14,7 +14,12 @@ do shift done -expected_result=$1 +test_name=$1 +expected_result=$2 +if [ -z "$test_name" ] +then + test_name=check +fi if [ -z "$expected_result" ] then expected_result=0 @@ -29,6 +34,11 @@ else options="$options $extra_options" fi +outfile=$test_name.out +logfile=check.out +reffile=$srcdir/output/$test_name.ref +options="$options -o $outfile" + builddir=`pwd` ltcmd="$builddir/../libtool --mode=execute -dlopen $builddir/../gedcom/libgedcom.la" GCONV_PATH=.:$GCONV_PATH @@ -38,15 +48,33 @@ ln -s $builddir/../data/new.ged . ln -s $builddir/../iconv/glibc/.libs/ANSI_Z39.47.so . ln -s $srcdir/../iconv/glibc/gconv-modules . rm -f core +echo "======================================================">> $logfile +echo "Performing test '$test_name'" >> $logfile $ltcmd $GEDCOM_TESTENV $builddir/src/updatetest $options result=$? rm gedcom.enc rm new.ged rm ANSI_Z39.47.so rm gconv-modules -if [ "$result" -eq "$expected_result" -a ! -r core ] + +echo "Result is $result (expected: $expected_result)" >> $logfile +if [ "$result" -ne "$expected_result" ] then - exit 0 -else exit 1 +else + if [ -r core ] + then + echo "Core file generated!" >> $logfile + exit 1 + else + if diff $outfile $reffile >/dev/null 2>>$logfile + then + echo "Output agrees with reference output" >> $logfile + rm $outfile + exit 0 + else + echo "Differences with reference output detected!" >> $logfile + exit 1 + fi + fi fi diff --git a/t/src/update.c b/t/src/update.c index fc0e079..d9f02a2 100644 --- a/t/src/update.c +++ b/t/src/update.c @@ -44,6 +44,7 @@ void show_help () printf("Options:\n"); printf(" -h Show this help text\n"); printf(" -q No output to standard output\n"); + printf(" -o File to generate output to (def. testgedcom.out)\n"); } int test_xref_functions() @@ -135,6 +136,7 @@ int test_xref_functions() int main(int argc, char* argv[]) { int result; + char* outfilename = NULL; if (argc > 1) { int i; @@ -146,6 +148,17 @@ int main(int argc, char* argv[]) else if (!strncmp(argv[i], "-q", 3)) { output_set_quiet(1); } + else if (!strncmp(argv[i], "-o", 3)) { + i++; + if (i < argc) { + outfilename = argv[i]; + } + else { + printf ("Missing output file name\n"); + show_help(); + exit(1); + } + } else { printf ("Unrecognized option: %s\n", argv[i]); show_help(); @@ -158,7 +171,7 @@ int main(int argc, char* argv[]) setlocale(LC_ALL, ""); gedcom_set_message_handler(gedcom_message_handler); - output_open(); + output_open(outfilename); result = gedcom_new_model(); if (result == 0) -- 2.30.2