1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

whence -a/type -a: report both function and built-in by same name

'whence -a' is documented to list all possible interpretations of a
command, but failed to list a built-in command if a shell function
by the same name exists or is marked undefined using 'autoload'.

src/cmd/ksh93/bltins/whence.c: whence():
- Refactor and separate the code for reporting functions and
  built-in commands so that both can be reported for one name.

src/cmd/ksh93/data/builtins.c: sh_optwhence[]:
- Correct 'whence --man' to document that:
  * 'type' is equivalent to 'whence -v'
  * '-a' output is like '-v'

src/cmd/ksh93/tests/builtins.sh:
- Test 'whence -a' with these combinations:
  * a function, built-in and external command
  * an undefined/autoload function, built-in and external command

Fixes https://github.com/ksh93/ksh/issues/83
This commit is contained in:
Martijn Dekker 2020-07-20 19:49:32 +01:00
parent 01c25cb14b
commit bc8b36faba
5 changed files with 45 additions and 20 deletions

View file

@ -753,6 +753,22 @@ $(whence -a -p printf | sed 's/^/printf is /')"
[[ $actual == $expected ]] || err_exit "'whence -a': incorrect output" \
"(expected $(printf %q "$expected"), got $(printf %q "$actual"))"
# 'whence -a'/'type -a' failed to list builtin if function exists: https://github.com/ksh93/ksh/issues/83
actual=$(printf() { :; }; whence -a printf)
expected="printf is a function
printf is a shell builtin
$(whence -a -p printf | sed 's/^/printf is /')"
[[ $actual == $expected ]] || err_exit "'whence -a': incorrect output for function+builtin" \
"(expected $(printf %q "$expected"), got $(printf %q "$actual"))"
# 'whence -a'/'type -a' failed to list builtin if autoload function exists: https://github.com/ksh93/ksh/issues/83
actual=$(autoload printf; whence -a printf)
expected="printf is an undefined function
printf is a shell builtin
$(whence -a -p printf | sed 's/^/printf is /')"
[[ $actual == $expected ]] || err_exit "'whence -a': incorrect output for autoload+builtin" \
"(expected $(printf %q "$expected"), got $(printf %q "$actual"))"
# ======
# 'cd ../.foo' should not exclude the '.' in '.foo'
(