commit: b6e0ded26d8aad17e6af1cf799f7165d943e88a3 Author: Kerin Millar <kfm <AT> plushkava <DOT> net> AuthorDate: Fri Aug 9 08:12:15 2024 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Sun Aug 11 10:11:02 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=b6e0ded2
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 <AT> plushava.net> Signed-off-by: Sam James <sam <AT> gentoo.org> test-functions | 14 +++++++++----- 1 file 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 "$@" }
