#!/bin/bash
set -e

pkg="bibutils"

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 debian/tests/Biblio.bib "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

# Three round-trips with conversions
bib2xml Biblio.bib | xml2bib > Bibliobxb.bib

bib2xml Biblio.bib | xml2end | end2xml | xml2bib > Bibliobxexb.bib

bib2xml Biblio.bib | xml2ris | ris2xml | xml2bib > Bibliobxrxb.bib

#Some tests
grep -E "(A|a)rticle.*stanton" Bibliobxb.bib
grep -E "(A|a)rticle.*stanton" Bibliobxexb.bib
grep -E "(A|a)rticle.*stanton" Bibliobxrxb.bib

grep -E "title.*econometrics" Bibliobxb.bib
grep -E "title.*econometrics" Bibliobxexb.bib
grep -E "title.*econometrics" Bibliobxrxb.bib
