#!/bin/sh
set -e

#run with
#autopkgtest ../socklog_2.1.2+repack-1_amd64.deb ../socklog-run_2.1.2+repack-1_all.deb  . --test-name=upstream-testsuite -- qemu ../autopkgtest.img

echo "importing upstream testsuite.."
#for file in socklog-*/src/*.check socklog-*/src/*.dist src/check-socklog-unix src/check-socklog-inet; do
for file in src/*.check src/*.dist ; do
    cp $file "$AUTOPKGTEST_TMP"
done
#cp socklog-*/src/check-diff "$AUTOPKGTEST_TMP"
cp src/check-diff "$AUTOPKGTEST_TMP"
cp compile/check-socklog-unix "$AUTOPKGTEST_TMP"
cp compile/check-socklog-inet "$AUTOPKGTEST_TMP"
echo "done"

#remove socklog socklog-check socklog-conf tryto uncat although they should not be in $PATH
#https://lists.debian.org/debian-mentors/2025/11/msg00172.html
for bin in socklog socklog-check socklog-conf tryto uncat; do
	rm  "command/$bin" || echo "can't find $bin under command/ : not removed"
	rm  "compile/$bin"  || echo "can't find $bin under compile/ : not removed"
done


cd "$AUTOPKGTEST_TMP"
echo "Running upstream testsuite.."
PATH=`pwd`:$PATH
# check-local, IT=socklog socklog-check socklog-conf tryto uncat
for i in socklog socklog-check socklog-conf tryto uncat ; do
	echo "Checking $i..."
	env - PATH="$PATH" ctmp="`pwd`/check-tmp" ./$i.check 2>&1 |cat -v >$i.local
	./check-diff $i && echo "..ok" || ( cat $i.local; echo "$i failed."; exit 1 ) || exit 1
done
echo "done"
