#!/bin/bash

# TODO: Make these work with local vdb instead of requiring /.
if [[ -n ${TRAVIS_OS_NAME} ]] ; then
	echo "TODO: Make it work on non-Gentoo system"
	exit 0
fi

. ../init.sh || exit 1

tests=(
	"q file -Cq /bin/bash /bin/XXXXX"
	"app-shells/bash"

	"q file -Co /bin/bash /bin/XXXXX"
	"/bin/XXXXX"

	"q file -Co -x bash /bin/bash"
	"/bin/bash"

	"q file -Co -x app-shells/bash /bin/bash"
	"/bin/bash"

	"q file -Co -x bash:0 /bin/bash"
	"/bin/bash"

	"q file -Co -x app-shells/bash:0 /bin/bash"
	"/bin/bash"

	"(cd /bin; q file -Cq bash)"
	"app-shells/bash"

	"(cd /; q file -Co bash)"
	"bash"
)

set -- "${tests[@]}"
while [[ $# -gt 0 ]] ; do
	test=$1; shift
	exp=$1; shift

	res=$(eval ${test})
	[[ "${res}" == "${exp}" ]]
	if ! tend $? "${test}" ; then
		(
		echo " - expected result was: ${exp}"
		echo " - actual result was:   ${res}"
		) > /dev/stderr
	fi
done

end
