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