diff --git a/test/test-lib.sh b/test/test-lib.sh index 548d534..2ee6249 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -18,7 +18,14 @@ if [ -z "$SHARNESS" ] || [ ! -f "$SHARNESS" ] ; then exit 1 fi +# Prevent sharness from adding the source directory to PATH +# since the scripts use unversioned python for their shebang +# but tests should run under the python with mercurial support +# so create an empty directory and strip it from PATH afterwards +SHARNESS_BUILD_DIRECTORY="$(mktemp -d)" . "$SHARNESS" +export PATH="${PATH#*:}" +rmdir "$SHARNESS_BUILD_DIRECTORY" if [ -n "$PYTHON" ] && "$PYTHON" -c 'import mercurial' 2> /dev/null ; then : Use chosen Python version @@ -29,7 +36,20 @@ elif python2 -c 'import mercurial' 2> /dev/null ; then elif python -c 'import mercurial' 2> /dev/null ; then PYTHON=python fi -test -n "$PYTHON" && test_set_prereq PYTHON +if [ -n "$PYTHON" ] ; then + test_set_prereq PYTHON + + # Change shebang on a copy of scripts to chosen Python version + TEST_BIN="$SHARNESS_TRASH_DIRECTORY/bin" + mkdir -p "$TEST_BIN" + for s in git-remote-hg git-hg-helper ; do + printf "%s\n" "#!/usr/bin/env $PYTHON" > "$TEST_BIN/$s" + tail -n +2 "$SHARNESS_TEST_DIRECTORY/../$s" >> "$TEST_BIN/$s" + chmod u+x "$TEST_BIN/$s" + done + export PATH="$TEST_BIN${PATH:+:$PATH}" + unset TEST_BIN +fi GIT_AUTHOR_EMAIL=author@example.com GIT_AUTHOR_NAME='A U Thor'