#! /bin/bash

set -x
set -e

cp -t $AUTOPKGTEST_TMP/ tests/*.cpp

cd $AUTOPKGTEST_TMP

cat > meson.build <<EOF
project('autopkgtest', ['cpp'],
  default_options : ['cpp_std=c++14'])

qt5_dep = dependency('qt5', modules: 'Core')
catch2_dep = dependency('catch2')
posixsignalmanager_dep = dependency('PosixSignalManager')

testlib = static_library('testlib', 'catch_main.cpp', dependencies: [catch2_dep])
test('tests', executable('tests', 'tests.cpp', link_with: [testlib],
     dependencies: [posixsignalmanager_dep, qt5_dep, catch2_dep]))

EOF

if ! meson setup _build ; then
    cp -r _build/meson-logs  $AUTOPKGTEST_ARTIFACTS
    exit 1
fi
if ! meson test -C _build ; then
    cp -r _build/meson-logs  $AUTOPKGTEST_ARTIFACTS
    exit 1
fi

cp -r _build/meson-logs  $AUTOPKGTEST_ARTIFACTS || true
