#!/bin/sh
set -e

echo "importing upstream testsuite.."
for file in runit-2.1.2/src/*.check runit-2.1.2/src/*.dist; do
    cp $file "$AUTOPKGTEST_TMP"
done
cp runit-2.1.2/src/check-diff "$AUTOPKGTEST_TMP"
# chpst.dist needs a patch, see d/patches/0027-Add-a-chpst-missing-option..
rm "$AUTOPKGTEST_TMP"/chpst.dist
cat >"$AUTOPKGTEST_TMP"/chpst.dist <<-\EOT
usage: chpst [-vVP012] [-u user[:group]] [-U user[:group]] [-b argv0] [-e dir] [-/ root] [-n nice] [-l|-L lock] [-m n] [-d n] [-o n] [-p n] [-f n] [-c n] [-t n] prog

100
$Id: f279d44141c981dd7535a12260efcf1ef7beed26 $
usage: chpst [-vVP012] [-u user[:group]] [-U user[:group]] [-b argv0] [-e dir] [-/ root] [-n nice] [-l|-L lock] [-m n] [-d n] [-o n] [-p n] [-f n] [-c n] [-t n] prog

100
test=1
0
0
0
0
0

EOT
echo "done"

cd "$AUTOPKGTEST_TMP"
echo "Running upstream testsuite.."
# check-local, IT = chpst runit runit-init runsv runsvchdir runsvdir sv svlogd utmpset
for i in chpst runit runit-init runsv runsvchdir runsvdir sv svlogd utmpset ; do
	echo "Checking $i..."
	if [ "$i" = runit-init ]; then
		PATH=/lib/runit/:$PATH ctmp="`pwd`/check-tmp" ./$i.check 2>&1 |cat -v >$i.local
	else
		ctmp="`pwd`/check-tmp" ./$i.check 2>&1 |cat -v >$i.local
	fi
	./check-diff $i && echo "..ok" || ( cat $i.local; echo "$i failed."; exit 1 ) || exit 1
done
echo "done"
