#!/bin/bash
set -e

CUR_DIR=`pwd`
if [ "$AUTOPKGTEST_TMP" = "" ] ; then
  AUTOPKGTEST_TMP=`mktemp -d /tmp/${pkg}-test.XXXXXX`
  trap "rm -rf $AUTOPKGTEST_TMP" 0 INT QUIT ABRT PIPE TERM
fi

cp -a ${CUR_DIR}/test/ $AUTOPKGTEST_TMP
cp -a ${CUR_DIR}/run_tests.sh $AUTOPKGTEST_TMP

cd $AUTOPKGTEST_TMP

# sambamba used a modified copy of shunit2, but in this case we need to substitute this variable
sed -i 's/\$1/\/usr\/bin\/sambamba/g' test/test_suite.sh

./test/test_suite.sh 2>&1 | tr '\r' '\n' > test.log
cat test.log
cat test.log | grep -q 'OK'

echo "PASS"
