Skip to content

Commit

Permalink
Fix zsh default srcdir support
Browse files Browse the repository at this point in the history
It turns that by adding zsh support in 00cb93e (Add initial support for
zsh, 2023-03-10) we disabled the feature enabled in 0bc8705 (Set proper
location of TEST_SRCDIR, 2022-09-07) for zsh.

In order for SHARNESS_TEST_SRCDIR to have a proper default in zsh, we
need to restore the previous semantics of $0.

Let's do that by storing the value of $0 before POSIX_ARGZERO is turned
on.

Helps issue #124.

Signed-off-by: Felipe Contreras <[email protected]>
  • Loading branch information
felipec committed Mar 6, 2024
1 parent ae72476 commit 2ac4954
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sharness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

if test -n "${ZSH_VERSION-}"
then
SHARNESS_SOURCE=$0
emulate sh -o POSIX_ARGZERO
else
# shellcheck disable=SC3028
SHARNESS_SOURCE=${BASH_SOURCE-$0}
fi

# Public: Current version of Sharness.
Expand All @@ -39,8 +43,7 @@ SHARNESS_TEST_DIRECTORY=$(cd "$SHARNESS_TEST_DIRECTORY" && pwd) || exit 1
# e.g. for testing Sharness itself.
export SHARNESS_TEST_DIRECTORY

# shellcheck disable=SC3028
: "${SHARNESS_TEST_SRCDIR:=$(cd "$(dirname "${BASH_SOURCE-$0}")" && pwd)}"
: "${SHARNESS_TEST_SRCDIR:=$(cd "$(dirname "$SHARNESS_SOURCE")" && pwd)}"
# Public: Source directory of test code and sharness library.
# This directory may be different from the directory in which tests are
# being run.
Expand Down

0 comments on commit 2ac4954

Please sign in to comment.