#! /bin/bash

set -x
set -e

cp -a src/tests $AUTOPKGTEST_TMP/tests

cd $AUTOPKGTEST_TMP

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

qt5_dep = dependency('qt5', modules: 'Core')
termpaint_dep = dependency('termpaint')
tuiwidgets_dep = dependency('TuiWidgets')
catch2_dep = dependency('catch2')

if catch2_dep.version().version_compare('>=3.0')
  catch2_dep = [catch2_dep, declare_dependency(compile_args: ['-DCATCH3'])]
endif

tests_as_installed = true

subdir('tests')

EOF

if ! meson _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
