summaryrefslogtreecommitdiff
path: root/regress/bin/ksh
diff options
context:
space:
mode:
authortb <tb@cvs.openbsd.org>2016-03-21 13:35:01 +0000
committertb <tb@cvs.openbsd.org>2016-03-21 13:35:01 +0000
commit6812a0d79be216cf7e477c5bf4ef68de11fed6e6 (patch)
treef8c5ad837f76be1ff8588094103b17ee4630e0bf /regress/bin/ksh
parentb035e3d07c38fac27521c14f1565c4dc21ba3de4 (diff)
More ksh POSIX compliance fixes by Martijn Dekker:
This simple patch makes the 'command' builtin POSIX-compliant and consistent with other current shells. It fixes two things: a) 'command -v' does not find shell reserved words (a.k.a. keywords). For instance, 'command -v select' outputs nothing but should output 'select'. b) 'command -pv' always outputs the path of an external command, even if 'command -p' would execute a builtin. For instance, 'command -p kill' executes the 'kill' builtin, as expected, but 'command -pv kill' outputs '/bin/kill'. The '-v' option is supposed to reflect what would actually be executed, so 'command -pv kill' should output 'kill'. The -p option sets the PATH to a default system value before doing the search, but that has no bearing on the fact that builtins take precedence over external commands. The patch fixes both issues for 'command' without affecting the behaviour of the ksh-specific builtin 'whence', which is handled by the same C function. Regression test added to obsd-regress.t. Issues found and fixed by Martijn Dekker, ok millert@
Diffstat (limited to 'regress/bin/ksh')
-rw-r--r--regress/bin/ksh/obsd-regress.t83
1 files changed, 82 insertions, 1 deletions
diff --git a/regress/bin/ksh/obsd-regress.t b/regress/bin/ksh/obsd-regress.t
index 26759c89cbb..8952ab0e91d 100644
--- a/regress/bin/ksh/obsd-regress.t
+++ b/regress/bin/ksh/obsd-regress.t
@@ -1,4 +1,4 @@
-# $OpenBSD: obsd-regress.t,v 1.2 2016/03/05 12:30:17 czarkoff Exp $
+# $OpenBSD: obsd-regress.t,v 1.3 2016/03/21 13:35:00 tb Exp $
#
# ksh regression tests from OpenBSD
@@ -274,6 +274,87 @@ stdin:
---
+name: command-pvV-posix-priorities
+description:
+ 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=$(command -p getconf PATH) || PATH=/bin:/usr/bin
+ alias foo="bar baz"
+ bar() { :; }
+ for word in 'if' 'foo' 'bar' 'set' 'true' 'ls'; do
+ command -v "$word"
+ command -pv "$word"
+ command -V "$word"
+ command -pV "$word"
+ done
+expected-stdout-pattern:
+ /^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
+ .*\/ls.*
+ .*\/ls.*
+ ls is a tracked alias for .*\/ls.*
+ ls is .*\/ls.*$/
+---
+
+name: whence-preserve-tradition
+description:
+ POSIX 'command' and ksh88/pdksh-specific 'whence' are handled by the
+ same c_whence() function. This regression test is to ensure that
+ the POSIX compatibility changes for 'command' (see previous test) do
+ not affect traditional 'whence' behaviour.
+stdin:
+ PATH=$(command -p getconf PATH) || PATH=/bin:/usr/bin
+ alias foo="bar baz"
+ bar() { :; }
+ for word in 'if' 'foo' 'bar' 'set' 'true' 'ls'; do
+ whence "$word"
+ whence -p "$word"
+ whence -v "$word"
+ whence -pv "$word"
+ done
+expected-stdout-pattern:
+ /^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
+ .*\/true.*
+ true is a shell builtin
+ true is a tracked alias for .*\/true.*
+ .*\/ls.*
+ .*\/ls.*
+ ls is a tracked alias for .*\/ls.*
+ ls is a tracked alias for .*\/ls.*$/
+---
+
name: shellopt-u-1
description:
Check that "$@" and "$*" are exempt from 'set -u' (nounset)