Restructure output from tests.
[gedcom-parse.git] / t / src / test_gom
1 #!/bin/sh
2 # $Id$
3 # $Name$
4
5 options="-q"
6 extra_options=
7 dmalloc=`which dmalloc`
8 dmalloc_tmp=dmalloc.env
9
10 while [ $# -gt 0 ]
11 do
12   case "$1" in
13     -*) extra_options="$extra_options $1";;
14     *)  break;;
15   esac
16   shift
17 done
18
19 file=$1
20 test_name=$2
21 expected_result=$3
22 if [ -z "$test_name" ]
23 then
24   test_name=check
25 fi
26 if [ -z "$expected_result" ]
27 then
28   expected_result=0
29 fi
30
31 # For use outside Makefile
32 if [ -z "$srcdir" ]
33 then
34   testfile=$file
35   srcdir=.
36   options=$extra_options
37 else
38   testfile=$srcdir/input/$file
39   options="$options $extra_options"
40 fi
41
42 outfile=$test_name.out
43 logfile=check.out
44 reffile=$srcdir/output/$test_name.ref
45 options="$options -o $outfile"
46
47 builddir=`pwd`
48 ltcmd="$builddir/../libtool --mode=execute -dlopen $builddir/../gedcom/libgedcom.la -dlopen $builddir/../gom/libgedcom_gom.la"
49 GCONV_PATH=.:$GCONV_PATH
50 export GCONV_PATH
51 ln -s $srcdir/../data/gedcom.enc .
52 ln -s $builddir/../iconv/glibc/.libs/ANSI_Z39.47.so .
53 ln -s $srcdir/../iconv/glibc/gconv-modules .
54 rm -f core
55 echo "======================================================">> $logfile
56 echo "Performing test '$test_name'" >> $logfile
57 if [ "$GOM_DMALLOC_TEST" = "" ]
58 then
59   $ltcmd $GEDCOM_TESTENV $builddir/src/gomtest $options $testfile
60 else
61   $dmalloc -b -l $GOM_DMALLOC_TEST -i 100 low > $dmalloc_tmp
62   . $dmalloc_tmp
63   rm $dmalloc_tmp
64   $ltcmd $GEDCOM_TESTENV $builddir/src/gomtest_static $options $testfile
65 fi
66 result=$?
67 rm gedcom.enc
68 rm ANSI_Z39.47.so
69 rm gconv-modules
70
71 echo "Result is $result (expected: $expected_result)" >> $logfile
72 if [ "$result" -ne "$expected_result" ]
73 then
74   exit 1
75 else
76   if [ -r core ]
77   then
78     echo "Core file generated!" >> $logfile
79     exit 1
80   else
81     if diff $outfile $reffile >/dev/null 2>>$logfile
82     then
83       echo "Output agrees with reference output" >> $logfile
84       rm $outfile
85       exit 0
86     else
87       echo "Differences with reference output detected!" >> $logfile
88       exit 1
89     fi
90   fi
91 fi