From f5c38f3a59eaf234a4e1670d9fc4f642e6a23157 Mon Sep 17 00:00:00 2001 From: Paul Wise Date: Wed, 31 Mar 2021 19:15:07 +0800 Subject: [PATCH] Run Python scripts under the chosen version The Python scripts have unversioned Python shebangs so tests will fail if the chosen Python version is not unversioned Python. Copy the scripts to tmp dirs and change the shebang to the chosen Python. Also prevent sharness from adding the unversioned Python scripts to PATH. --- test/test-lib.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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'