#!/bin/bash
set -e

pkg=gatb-core
CUR_DIR=`pwd`

export LC_ALL=C.UTF-8
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}/${pkg}/examples "${AUTOPKGTEST_TMP}"
cp -a ${CUR_DIR}/${pkg}/test/db "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

DB_DIR=${AUTOPKGTEST_TMP}/db

code_snippets=($(find ./examples -name "*1.cpp"))
for code_snippet in ${code_snippets[*]}
do
        prg_name=`echo $code_snippet | cut -d'/' -f4 | cut -d'.' -f1`
# Compiling using installed libs
    g++ $code_snippet -Iinclude -Llib -lgatbcore `pkg-config --libs hdf5`  -lhdf5 -lmpi  -ldl -lz -lpthread  -std=c++0x -O3 -o $prg_name
done

echo -e "f6f63f16384efd47a059566413617770  kmer.fa" >> checksums

echo -e "Running Tests"

echo -e "Test 1"
./iterators1

echo -e "Test 2"
./bank1 ${DB_DIR}/reads1.fa
./bank11 -kmer-size 4 -out kmer.fa

echo -e "Test 3"
./debruijn1 -in ${DB_DIR}/reads1.fa
./debruijn11
./debruijn21 -graph ${DB_DIR}/celegans_reads.h5

echo -e "Test 4"
./kmer1
./kmer11 -in ${DB_DIR}/reads1.fa

echo -e "Test 5"
./multithreading1

echo -e "Test 6"
./observer1

echo -e "Test 7"
./storage1

echo -e "Test 8"
./traversal1 -graph ${DB_DIR}/celegans_reads.h5

md5sum --check checksums
echo "PASS"
