#!/bin/sh

echo "${TEST_NAME} -- test whether eselect-python is respected"

# Usually, the newest version of Python is eselected. For that reason,
# this test makes sense only if Python 3 is the main Python interpreter
# (and thus a 'better' implementation could be selected).

set -- ${PYTHON_IMPLS}

SEL_PY=$(get_eselected)

while true; do
	if [ ${#} -lt 2 ]; then
		# we can't test a preference without at least two impls ;)
		echo 'Best Python eselected, unable to perform test.' >&2
		do_exit 77
	fi

	# Repeat until we find the eselected python.
	if [ "${1}" = "${SEL_PY}" ]; then
		break
	else
		shift
	fi
done

ESELECT=${1}
BETTER=${2}

echo "other impl: ${BETTER}" >&2

unset EPYTHON

write_impl "${ESELECT}" "#!/usr/bin/env true"
write_impl "${BETTER}"  "#!/usr/bin/env false"

do_test "${TEST_TMP}"
