#!/bin/sh
# autopkgtest check: build and run a program against sumalibs. We check that 
# it builds and that it behaves well on a very simple reading exercise.
# (C) 2020 Pierre Gruet.
# Author: Pierre Gruet <pgt@debian.org>

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR

cat <<EOF > test.fasta
>SEQ1
ACGATCGCACGCATCGTCAG
>SEQ2
ACGTAGCTAGCA
EOF

cat <<EOF > main.c
#include <stdio.h>
#include <libfasta/sequence.h>

int main()
{
        fastaSeqCount n;
        n=seq_readAllSeq2("test.fasta", 1, 1);
        printf("%d sequences are read\n", n.count);
        
        return 0;
}
EOF

gcc -c -o main.o main.c
gcc -o testPrg main.o -lsuma

echo "Build done"

if [ -x testPrg ]; then
  ./testPrg |
  sed -n 's/.sequences.*//p' |
  grep "2"
  
  if [ $? -ne 0 ]; then
    exit 1
  fi
fi

