mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
whence -f: ignore functions (#137)
According to 'whence --man', 'whence -f' should ignore functions:
-f Do not check for functions.
Right now this is only accomplished partially. As of commit
a329c22d
'whence -f' avoids any output when encountering a
function (in ksh93u+ 'whence -f' has incorrect output). The
return value is still wrong though:
$ foo() { true; }
$ whence -f foo; echo $?
0
This commit fixes the return value and makes 'type -f' error out
when given a function (like in Bash).
src/cmd/ksh93/bltins/whence.c:
- If -f was passed, set 'cp' to NULL since functions should be
ignored (as documented).
- Simplify return value by avoiding bitwise logic.
src/cmd/ksh93/tests/builtins.sh:
- Add regression tests for 'whence -f' and 'type -f'.
Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
parent
7e6bbf85b6
commit
8a34fc40e6
4 changed files with 33 additions and 7 deletions
|
@ -841,6 +841,27 @@ actual=$(hash -r; alias ls='echo ALL UR F1LEZ R G0N3'; hash ls; whence -a ls)
|
|||
[[ $actual == "$expect" ]] || err_exit "'whence -a' does not report tracked alias if alias exists" \
|
||||
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
|
||||
|
||||
# 'whence -f' should ignore functions
|
||||
foo_bar() { true; }
|
||||
actual="$(whence -f foo_bar)"
|
||||
whence -f foo_bar >/dev/null && err_exit "'whence -f' doesn't ignore functions (got '$(printf %q "$actual")')"
|
||||
|
||||
# whence -vq/type -q must be tested as well
|
||||
actual="$(type -f foo_bar 2>&1)"
|
||||
type -f foo_bar >/dev/null 2>&1 && err_exit "'type -f' doesn't ignore functions (got '$(printf %q "$actual")')"
|
||||
type -qf foo_bar && err_exit "'type -qf' doesn't ignore functions"
|
||||
|
||||
# Test the exit status of 'whence -q'
|
||||
(
|
||||
mkdir "$tmp/fakepath"
|
||||
ln -s "${ whence -p cat ;}" "$tmp/fakepath"
|
||||
ln -s "${ whence -p ls ;}" "$tmp/fakepath"
|
||||
PATH="$tmp/fakepath"
|
||||
whence -q cat nonexist ls && err_exit "'whence -q' has the wrong exit status"
|
||||
whence -q cat nonexist && err_exit "'whence -q' has the wrong exit status"
|
||||
whence -q nonexist && err_exit "'whence -q' has the wrong exit status"
|
||||
)
|
||||
|
||||
# ======
|
||||
# 'cd ../.foo' should not exclude the '.' in '.foo'
|
||||
# https://bugzilla.redhat.com/889748
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue