#!/bin/sh

echo "${TEST_NAME} -- test whether EPYTHON is respected"

set -- ${PYTHON_IMPLS}

unset EPYTHON
while true; do
	if [ ${#} -lt 2 ]; then
		# we can't test a preference without at least two impls ;)
		echo 'Not enough implementations to perform test.' >&2
		do_exit 77
	fi

	if [ -z "${EPYTHON}" ]; then
		# EPYTHON can't be one of eselected pythons, otherwise the result
		# would be inconclusive.
		if ! is_preferred "${1}"; then
			export EPYTHON="${1}"
		fi
		shift
	else
		# The other impl shouldn't be disabled to get conclusive result.
		if ! is_disabled "${1}"; then
			BETTER=${1}
			break
		fi
		shift
	fi
done

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

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

do_test "${TEST_TMP}"
