summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2024-08-09 09:12:15 +0100
committerSam James <sam@gentoo.org>2024-08-11 11:11:02 +0100
commitb6e0ded26d8aad17e6af1cf799f7165d943e88a3 (patch)
tree104e35a8f79ab67536bff62e8841288c536fc916
parentRender _update_time() a no-op for the yash shell (diff)
downloadgentoo-functions-b6e0ded26d8aad17e6af1cf799f7165d943e88a3.tar.gz
gentoo-functions-b6e0ded26d8aad17e6af1cf799f7165d943e88a3.tar.bz2
gentoo-functions-b6e0ded26d8aad17e6af1cf799f7165d943e88a3.zip
test-functions: account for the potential absence of test(1) as a builtin
Presently, the test_whenceforth() function potects itself from being adversely affected by printf(1) not being a builtin utility. Consider the following test. PATH=. whenceforth -x newer/file Owing to the modification of PATH, it becomes impossible to execute any of the standard utilities unless they happen to be builtins. The workaround is to temporarily define printf as a function which duly executes the external utility. Having run the test suite with the yash shell, it has served as a sharp reminder that one cannot assume that test(1) is always available as a builtin either. In fact, yash implements test(1) as a "substitutative built-in command". Below is the relevant material from its manual. - https://magicant.github.io/yash/doc/builtin.html#types - https://magicant.github.io/yash/doc/exec.html#search - https://magicant.github.io/yash/doc/index.html#builtins It is a curious thing, to say the least. Essentially, substitutative builtins can only be used for as long as an executable of the same name can be found in PATH. Since the purpose of test_whenceforth() is not to directly evaluate the behaviour of the test(1) utility, this commit implements the same safeguard for test(1) as is present for printf(1). Signed-off-by: Kerin Millar <kfm@plushava.net> Signed-off-by: Sam James <sam@gentoo.org>
-rwxr-xr-xtest-functions14
1 files changed, 9 insertions, 5 deletions
diff --git a/test-functions b/test-functions
index c96ac48..7c848c1 100755
--- a/test-functions
+++ b/test-functions
@@ -687,14 +687,17 @@ test_whenceforth() {
else
test_description="PATH=${path} whenceforth $(quote_args "$@")"
(
- # If necessary, conduct the test with a printf
- # function in effect, duly covering shells that
- # do not implement it as a builtin. Otherwise,
- # it could become unavailable on account of the
- # various values of PATH being tested.
+ # If necessary, declare functions to cover the
+ # utilities that might otherwise be unavailable
+ # on account of the various values of PATH
+ # being tested. It cannot be assumed that the
+ # utilities in question are builtins.
case ${printf_cmd} in
/*) printf() { "${printf_cmd}" "$@"; }
esac
+ case ${test_cmd} in
+ /*) test() { "${test_cmd}" "$@"; }
+ esac
# shellcheck disable=2030
PATH=${path}
whenceforth "$@" >/dev/null
@@ -703,6 +706,7 @@ test_whenceforth() {
}
printf_cmd=$(command -v printf)
+ test_cmd=$(command -v test)
iterate_tests 5 "$@"
}