Thorsten Glaser schreef op 26-02-16 om 21:57:
> In the end, I decided I don’t like the code and rewrote it entirely,
> separating options processing, simplifying, etc. but thanks anyway!
Yes, that code looks much cleaner. No more opaque mixing of two
different command's option logic.
I also missed something in that patch -- aliases still weren't handled
correctly. But your new code fixes that too.
I also submitted a patch to OpenBSD ksh for this and in the process I
wrote a couple of more robust regression tests, one to make sure
'command' behaves correctly and the other to check 'whence' behaviour
hasn't changed. Here they are as a patch against mksh, latest cvs. (They
pass.)
- M.
cvs diff: Diffing .
Index: check.t
===================================================================
RCS file: /cvs/src/bin/mksh/check.t,v
retrieving revision 1.726
diff -u -r1.726 check.t
--- check.t 1 Mar 2016 18:30:25 -0000 1.726
+++ check.t 5 Mar 2016 03:47:29 -0000
@@ -12196,13 +12196,75 @@
after 0='swc' 1='二' 2=''
= done
---
-name: command-path
+name: command-pvV-posix-priorities
description:
- Check 'command -p' is not 'whence -p'
-stdin:
- command -pv if
+ For POSIX compatibility, command -v should find aliases and reserved
+ words, and command -p[vV] should find aliases, reserved words, and
+ builtins over external commands.
+stdin:
+ PATH=/bin:/usr/bin
+ alias foo="bar baz"
+ bar() { :; }
+ for word in 'if' 'foo' 'bar' 'set' 'true'; do
+ command -v "$word"
+ command -pv "$word"
+ command -V "$word"
+ command -pV "$word"
+ done
+expected-stdout:
+ if
+ if
+ if is a reserved word
+ if is a reserved word
+ alias foo='bar baz'
+ alias foo='bar baz'
+ foo is an alias for 'bar baz'
+ foo is an alias for 'bar baz'
+ bar
+ bar
+ bar is a function
+ bar is a function
+ set
+ set
+ set is a special shell builtin
+ set is a special shell builtin
+ true
+ true
+ true is a shell builtin
+ true is a shell builtin
+---
+name: whence-preserve-tradition
+description:
+ This regression test is to ensure that the POSIX compatibility
+ changes for 'command' (see previous test) do not affect traditional
+ 'whence' behaviour.
+stdin:
+ PATH=/bin:/usr/bin
+ alias foo="bar baz"
+ bar() { :; }
+ for word in 'if' 'foo' 'bar' 'set' 'true'; do
+ whence "$word"
+ whence -p "$word"
+ whence -v "$word"
+ whence -pv "$word"
+ done
expected-stdout:
if
+ if is a reserved word
+ if not found
+ 'bar baz'
+ foo is an alias for 'bar baz'
+ foo not found
+ bar
+ bar is a function
+ bar not found
+ set
+ set is a special shell builtin
+ set not found
+ true
+ /usr/bin/true
+ true is a shell builtin
+ true is a tracked alias for /usr/bin/true
---
name: duffs-device
description: