Skip to content

Commit

Permalink
tests: avoid use of non-portable which
Browse files Browse the repository at this point in the history
which is not a standard POSIX utility, and indeed, each of these test scripts
uses #!/bin/bash as its shebang, so we can use `type -P` which has the same
behaviour as `which` for free.

(If the tests used POSIX shell, we could do `command -v`, its only caveat is
that it'll pick up functions in the user's shell, which doesn't matter 99% of
the time anyway.)

Distributions like Debian [0] and Gentoo [1] are looking to remove `which`
from their base set of packages.

[0] https://lwn.net/Articles/874049/
[1] https://bugs.gentoo.org/646588

Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
thesamesam authored and pcmoore committed Jan 7, 2024
1 parent 12a9e9f commit 47ca644
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/38-basic-pfc_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
function check_deps() {
[[ -z "$1" ]] && return
which "$1" >& /dev/null
type -P "$1" >& /dev/null
return $?
}

Expand Down
2 changes: 1 addition & 1 deletion tests/55-basic-pfc_binary_tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
function check_deps() {
[[ -z "$1" ]] && return
which "$1" >& /dev/null
type -P "$1" >& /dev/null
return $?
}

Expand Down
2 changes: 1 addition & 1 deletion tests/regression
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ GLBL_SYS_API="../tools/scmp_api_level"
#
function check_deps() {
[[ -z "$1" ]] && return
which "$1" >& /dev/null
type -P "$1" >& /dev/null
return $?
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testgen
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#
function verify_deps() {
[[ -z "$1" ]] && return
if ! which "$1" >& /dev/null; then
if ! type -P "$1" >& /dev/null; then
echo "error: install \"$1\" and include it in your \$PATH"
exit 1
fi
Expand Down

0 comments on commit 47ca644

Please sign in to comment.