From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 40F9A159C9C for ; Sun, 11 Aug 2024 10:11:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 852D92BC0ED; Sun, 11 Aug 2024 10:11:15 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 689172BC0ED for ; Sun, 11 Aug 2024 10:11:15 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 824C8340BEF for ; Sun, 11 Aug 2024 10:11:14 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C2D311EED for ; Sun, 11 Aug 2024 10:11:10 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1723371062.b6e0ded26d8aad17e6af1cf799f7165d943e88a3.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: test-functions X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: b6e0ded26d8aad17e6af1cf799f7165d943e88a3 X-VCS-Branch: master Date: Sun, 11 Aug 2024 10:11:10 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 21fbfe37-1ab5-4e38-8d2b-3bb2cc3e2ba6 X-Archives-Hash: 3c0f580bff633743b21f6fa5e695eac7 commit: b6e0ded26d8aad17e6af1cf799f7165d943e88a3 Author: Kerin Millar plushkava net> AuthorDate: Fri Aug 9 08:12:15 2024 +0000 Commit: Sam James gentoo 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 plushava.net> Signed-off-by: Sam James 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 "$@" }