Debian Codegraph @

test/cxx/testone

raw symbols SCIP
1 #!/bin/sh -
2 # $Id$
3 #
4 # Run just one C++ regression test, the single argument
5 # is the basename of the test, e.g. TestRpcServer
6
7 error()
8 {
9 echo '' >&2
10 echo "C++ regression error: $@" >&2
11 echo '' >&2
12 ecode=1
13 }
14
15 # compares the result against the good version,
16 # reports differences, and removes the result file
17 # if there are no differences.
18 #
19 compare_result()
20 {
21 good="$1"
22 latest="$2"
23 if [ ! -e "$good" ]; then
24 echo "Note: $good does not exist"
25 return
26 fi
27 tmpout=/tmp/blddb$$.tmp
28 diff "$good" "$latest" > $tmpout
29 if [ -s $tmpout ]; then
30 nbad=`grep '^[0-9]' $tmpout | wc -l`
31 error "$good and $latest differ in $nbad places."
32 else
33 rm $latest
34 fi
35 rm -f $tmpout
36 }
37
38 ecode=0
39 stdinflag=n
40 gdbflag=n
41 CXX=${CXX:-c++}
42 LIBS=${LIBS:-}
43
44 # remove any -c option in the CXXFLAGS
45 CXXFLAGS="`echo " ${CXXFLAGS} " | sed -e 's/ -c //g'`"
46
47 # determine the prefix of the install tree
48 prefix=""
49 while :
50 do
51 case "$1" in
52 --prefix=* )
53 prefix="`echo $1 | sed -e 's/--prefix=//'`"; shift
54 LIBS="-L$prefix/lib -ldb_cxx $LIBS"
55 CXXFLAGS="-I$prefix/include $CXXFLAGS"
56 export LD_LIBRARY_PATH="$prefix/lib:$LD_LIBRARY_PATH"
57 ;;
58 --stdin )
59 stdinflag=y; shift
60 ;;
61 --gdb )
62 CXXFLAGS="-g $CXXFLAGS"
63 gdbflag=y; shift
64 ;;
65 * )
66 break
67 ;;
68 esac
69 done
70
71 if [ "$#" = 0 ]; then
72 echo 'Usage: testone [ --prefix=<dir> | --stdin ] TestName'
73 exit 1
74 fi
75 name="$1"
76
77 # compile
78 rm -rf TESTDIR; mkdir TESTDIR
79 cd ./TESTDIR
80
81 ${CXX} ${CXXFLAGS} -o $name ../$name.cpp ${LIBS} > ../$name.compileout 2>&1
82 if [ $? != 0 -o -s ../$name.compileout ]; then
83 error "compilation of $name failed, see $name.compileout"
84 exit 1
85 fi
86 rm -f ../$name.compileout
87
88 # find input and error file
89 infile=../$name.testin
90 if [ ! -f $infile ]; then
91 infile=/dev/null
92 fi
93
94 # run and diff results
95 rm -rf TESTDIR
96 if [ "$gdbflag" = y ]; then
97 if [ -s $infile ]; then
98 echo "Input file is $infile"
99 fi
100 gdb ./$name
101 exit 0
102 elif [ "$stdinflag" = y ]; then
103 ./$name >../$name.out 2>../$name.err
104 else
105 ./$name <$infile >../$name.out 2>../$name.err
106 fi
107 cd ..
108
109 testerr=$name.testerr
110 if [ ! -f $testerr ]; then
111 testerr=/dev/null
112 fi
113
114 testout=$name.testout
115 if [ ! -f $testout ]; then
116 testout=/dev/null
117 fi
118
119 compare_result $testout $name.out
120 compare_result $testerr $name.err
121 rm -rf TESTDIR
122 exit $ecode