#!/bin/sh

set -e -u

# copy tests, test data and cert fixtures
cp --verbose --archive tests/ certs/ "$AUTOPKGTEST_TMP"
cd "$AUTOPKGTEST_TMP"

# set up writable HOME and D-Bus session for gsettings
export HOME="$AUTOPKGTEST_TMP/home"
export GNOMINT_CLI=/usr/bin/gnomint-cli
mkdir -p "$HOME"
eval $(dbus-launch --sh-syntax)

# disarm -e to ensure all tests are run even if some fail
set +e
RETVAL=0

for t in tests/check_cli_*.*; do
	echo "$t:"
	case "$t" in
		*.py) python3 "$t" 2>&1 ;;
		*)    srcdir=tests /bin/sh "$t" 2>&1 ;;
	esac
	rc=$?
	# exit code 77 means SKIP; treat as success
	[ "$rc" = 77 ] && rc=0
	RETVAL=$((RETVAL + rc))
done

exit $RETVAL
