#!/bin/bash
set -e

pkg=libmio-dev

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
  # shellcheck disable=SC2064
fi

cp -a /usr/share/doc/${pkg}/examples/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

# Build and run the upstream test and example against the installed header.
# Each one gets its own directory because both of them write files.
for src in test.cpp example.cpp ; do
    name=$(basename "${src}" .cpp)
    mkdir -p "${name}"
    ( cd "${name}" && g++ -O2 -std=c++11 -o "${name}" "../${src}" && "./${name}" )
done

# See the autopkgtest documentation at
# https://salsa.debian.org/salsa-ci-team/pipeline/-/blob/master/README.md
