#!/bin/sh
#
# run parrot tests under run-yamd
#
# $expect below is currently:
# - 3 stdio handles
# - 1 summary line

cleanup() {
	mv parrot.orig parrot
	exit
}

trap cleanup 1 2 3
mv parrot parrot.orig
echo "run-yamd -l2 -f -n ./parrot.orig  \$@ 2>&1 | perl -ne'
	BEGIN { undef $/; $|=1; };
	my \$expect = 3 + 1;
	my \$found = 0;
	my \$err = 0;
	print \$1 if (/\*{9,9}\n(.*?)\*{9,9}/s);
	while (/WARNING/g) { ++\$found };
	\$err++ if (/ERROR/);
	print qq(\nLEAKs \$found\n) if \$found > \$expect;
	print qq(\nERROR\n) if \$err;
	1;'" > parrot
chmod 755 parrot
perl t/harness --gc-debug --running-make-test --leak-test $@
cleanup
