#!/bin/bash

d=$PWD
[[ $PORTDIR == "" ]] && PORTDIR=$(portageq envvar PORTDIR)
cd ${PORTDIR}/metadata/cache || { echo SKIPPED; exit 0 ; }

if [[ $1 == -v ]] ; then
	find . -mindepth 2 -type f -printf '%P\n%f\n' | while read line ; do
		echo "TESTING $line: "
		"$d"/q "${line}"
	done
	exit 0
fi

echo -n "atom_explode():"
time find . -mindepth 2 -type f -printf '%P\n%f\n' | "$d"/q > "$d"/me || exit $?
echo

echo -n "portage:"
time find . -mindepth 2 -type f -printf '%P\n%f\n' | "$d"/atom-explode.py > "$d"/py || exit $?
echo

if diff -U 0 "$d"/me "$d"/py ; then
	echo "PASSED"
else
	echo "FAIL ! :("
fi
