1#!/bin/sh -
2#
3# $Id: chk.cxxtests,v 12.0 2004/11/17 03:44:48 bostic Exp $
4#
5# Check to make sure that regression tests for C++ run.
6
7TEST_CXX_SRCDIR=../test/scr015  # must be a relative directory
8
9# All paths must be relative to a subdirectory of the build directory
10LIBS="-L.. -ldb_cxx"
11CXXFLAGS="-I.. -I../../dbinc"
12
13[ `uname` = "Linux" ] && LIBS="$LIBS -lpthread"
14
15# Test must be run from a local build directory, not from a test
16# directory.
17cd ..
18[ -f db_config.h ] || {
19	echo 'FAIL: chk.cxxtests must be run from a local build directory.'
20	exit 1
21}
22[ -d ../env ] || {
23	echo 'FAIL: chk.cxxtests must be run from a local build directory.'
24	exit 1
25}
26[ -f libdb.a ] || make libdb.a || {
27	echo 'FAIL: unable to build libdb.a'
28	exit 1
29}
30[ -f libdb_cxx.a ] || make libdb_cxx.a || {
31	echo 'FAIL: unable to build libdb_cxx.a'
32	exit 1
33}
34CXX=`sed -e '/^CXX=/!d' -e 's/^CXX=//' -e 's/.*mode=compile *//' Makefile`
35echo "  ====== cxx tests using $CXX"
36testnames=`cd $TEST_CXX_SRCDIR; ls *.cpp | sed -e 's/\.cpp$//'`
37
38for testname in $testnames; do
39	if grep -x $testname $TEST_CXX_SRCDIR/ignore > /dev/null; then
40		echo "    **** cxx test $testname ignored"
41		continue
42	fi
43
44	echo "    ==== cxx test $testname"
45	rm -rf TESTCXX; mkdir TESTCXX
46	cd ./TESTCXX
47	testprefix=../$TEST_CXX_SRCDIR/$testname
48
49	${CXX} ${CXXFLAGS} -o $testname $testprefix.cpp ${LIBS} > ../$testname.compileout 2>&1 || {
50		echo "FAIL: compilation of $testname failed, see ../$testname.compileout"
51		exit 1
52	}
53	rm -f ../$testname.compileout
54	infile=$testprefix.testin
55	[ -f $infile ] || infile=/dev/null
56	goodoutfile=$testprefix.testout
57	[ -f $goodoutfile ] || goodoutfile=/dev/null
58	gooderrfile=$testprefix.testerr
59	[ -f $gooderrfile ] || gooderrfile=/dev/null
60	./$testname <$infile >../$testname.out 2>../$testname.err
61	cmp ../$testname.out $goodoutfile > /dev/null || {
62		echo "FAIL: $testname output differs: see ../$testname.out, $goodoutfile"
63		exit 1
64	}
65	cmp ../$testname.err $gooderrfile > /dev/null || {
66		echo "FAIL: $testname error differs: see ../$testname.err, $gooderrfile"
67		exit 1
68	}
69	cd ..
70	rm -f $testname.err $testname.out
71done
72rm -rf TESTCXX
73exit 0
74