#!/bin/sh

echo "${TEST_NAME} -- test whether Python wrapper sets sys.argv[0] correctly"

set -- ${PYTHON_IMPLS}

while true; do
	if [ ${#} -lt 1 ]; then
		echo 'No working Python interpreter found (?!)' >&2
		do_exit 77
	fi

	# We have to have the proper Python version installed.
	if ! "${1}" --version >&2; then
		shift
	else
		break
	fi
done

MY_PYTHON=${1}

echo "Python used: ${MY_PYTHON}" >&2

write_impl "${MY_PYTHON}" "import sys; print(sys.argv[0])"

# The value should be the same as if variant was run directly.
V_EXP=$("${MY_PYTHON}" "${TEST_DIR}/${MY_PYTHON}/${TEST_TMP}")
V_GOT=$("${MY_PYTHON}" "${TEST_DIR}/${TEST_TMP}")

echo "Expected: ${V_EXP}" >&2
echo "Received: ${V_GOT}" >&2
if [ "${V_EXP}" = "${V_GOT}" ]; then
	echo "Correct!" >&2
	do_exit 0
else
	echo "No match." >&2
	do_exit 1
fi
