#!/bin/sh

# run upstream's unit tests with Debian-supplied dependencies

# FIXME: right now this fails hard because many prerequisites are only
# handled in `make test`

set -e
set -u
set -x

BUILD_DIR="${PWD}/_build"
DH_OPTIONS="-O--buildsystem=golang -O--builddirectory=$BUILD_DIR"
APTLY_DIR="${BUILD_DIR}/src/github.com/aptly-dev/aptly"

dpkg-source --before-build .

dh_update_autotools_config $DH_OPTIONS
dh_autoreconf $DH_OPTIONS
dh_auto_configure $DH_OPTIONS

dpkg-parsechangelog --show-field Version | perl -pe 's/\n//' >| ${APTLY_DIR}/VERSION
find . -name VERSION

mkdir -p ${APTLY_DIR}/debian
cp debian/aptly.conf ${APTLY_DIR}/debian/

dh_auto_build $DH_OPTIONS

export PATH=${BUILD_DIR}/bin:$PATH

dh_auto_test $DH_OPTIONS --no-parallel
