1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 19:52:20 +00:00

tests/path.sh: fix spurious 'whence -a' test failures

A recent change in Github's Ubuntu test runners exposed a problem
in the way the all_paths test function replicates 'whence -a'
functionality, causing spurious regression test failures.
The problem occurs when e.g. /bin is a symlink to /usr/bin, but
both are in $PATH. The all_paths function treats them as separate
but 'whence -a' detects a duplicate and will not output /usr/bin/*.
I have not succeeded in making all_paths match 'whence -a' exactly.

src/cmd/ksh93/tests/path.sh: function all_paths:
- Using the -ef test expression operator, remove entries from $PATH
  that point to the same directory as another entry in $PATH (e.g.
  when /bin is a symlink to /usr/bin but both are in $PATH).
  Avoiding such dupes works around the problem.
This commit is contained in:
Martijn Dekker 2020-12-20 16:47:11 +00:00
parent cda1976e4c
commit 737438a30f

View file

@ -29,6 +29,28 @@ Command=${0##*/}
integer Errors=0
[[ -d $tmp && -w $tmp && $tmp == "$PWD" ]] || { err\_exit "$LINENO" '$tmp not set; run this from shtests. Aborting.'; exit 1; }
# to avoid spurious test failures with 'whence -a' tests, we need
# to remove any duplicate paths to the same directory from $PATH.
function rm_path_dups
{
typeset IFS=':' p seen s newpath
set -o noglob
p=$PATH: # IFS field splitting discards a final empty field; add one to avoid that
for p in $p
do if [[ -z $p ]]
then # empty $PATH element == current dir
p='.'
fi
for s in $seen
do [[ $p -ef $s ]] && continue 2
done
newpath=${newpath:+$newpath:}$p
seen=$seen$p:
done
PATH=$newpath
}
rm_path_dups
PATH_orig=$PATH
# output all paths to a command, skipping duplicates in $PATH