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 C31CE1581D3 for ; Sat, 18 May 2024 16:06:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BDE94E2A16; Sat, 18 May 2024 16:06:51 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 A71DFE2A16 for ; Sat, 18 May 2024 16:06:51 +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) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BB4E133BE18 for ; Sat, 18 May 2024 16:06:50 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 286571AA9 for ; Sat, 18 May 2024 16:06:49 +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: <1716048405.18e702eb8d32695dc503fc272d23e21cad7a6b12.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh test-functions X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 18e702eb8d32695dc503fc272d23e21cad7a6b12 X-VCS-Branch: master Date: Sat, 18 May 2024 16:06:49 +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: b04f3de5-3085-44be-b0ae-22face44805b X-Archives-Hash: f033efd9a3f822c537edb634a5534286 commit: 18e702eb8d32695dc503fc272d23e21cad7a6b12 Author: Kerin Millar plushkava net> AuthorDate: Sat May 18 16:03:46 2024 +0000 Commit: Sam James gentoo org> CommitDate: Sat May 18 16:06:45 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=18e702eb Separate some edo() code into a _print_args() helper function Further, make test-functions use _print_args() and jettison the inferior print_args() function that it was previously using. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> functions.sh | 33 +++++++++++++++++++-------------- test-functions | 18 +++++++++--------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/functions.sh b/functions.sh index db3314a..462db97 100644 --- a/functions.sh +++ b/functions.sh @@ -93,20 +93,7 @@ ebegin() # be made to exit by calling the die function. # edo() { - # Approximate the effect of ${param@Q} bash expansion. - genfun_cmd=$( - awk -v q=\' -f - -- "$@" <<-'EOF' - BEGIN { - argc = ARGC - ARGC = 1 - for (i = 1; i < argc; i++) { - arg = ARGV[i] - gsub(q, q "\\" q q, arg) - printf("'%s' ", arg) - } - } - EOF - ) + genfun_cmd=$(_print_args "$@") einfo "${genfun_cmd% }" "$@" || die "Failed to run command: ${genfun_cmd% }" } @@ -539,6 +526,24 @@ _is_visible() ! case $1 in *[[:graph:]]*) false ;; esac } +# +# Prints the positional parameters in a manner that approximates the behaviour +# of the ${*@Q} expansion in bash. +# +_print_args() { + awk -v q=\' -f - -- "$@" <<-'EOF' + BEGIN { + argc = ARGC + ARGC = 1 + for (i = 1; i < argc; i++) { + arg = ARGV[i] + gsub(q, q "\\" q q, arg) + printf("'%s' ", arg) + } + } + EOF +} + # # Determines whether the terminal on STDIN is able to report its dimensions. # Upon success, the number of columns shall be stored in genfun_cols. diff --git a/test-functions b/test-functions index 0c0bb45..24a7527 100755 --- a/test-functions +++ b/test-functions @@ -41,7 +41,7 @@ test_chdir() { callback() { shift - test_description="chdir $(print_args "$@")" + test_description="chdir $(_print_args "$@")" if [ "$BASH" ]; then # shellcheck disable=3044 shopt -s cdable_vars @@ -60,7 +60,7 @@ test_chdir_noop() { callback() { shift - test_description="chdir $(print_args "$@")" + test_description="chdir $(_print_args "$@")" chdir "$@" \ && test "$PWD" = "$OLDPWD" \ || { cd - >/dev/null; false; } @@ -195,7 +195,7 @@ test_is_older_than() { callback() { shift - test_description="is_older_than $(print_args "$@")" + test_description="is_older_than $(_print_args "$@")" is_older_than "$@" } @@ -221,7 +221,7 @@ test_get_bootparam() { callback() { cmdline=$2 shift 2 - test_description="get_bootparam $(print_args "$@")" + test_description="get_bootparam $(_print_args "$@")" printf '%s\n' "${cmdline}" | get_bootparam "$@" } @@ -246,7 +246,7 @@ test_esyslog() { should_log=$2 shift 2 logged=0 - test_description="esyslog $(print_args "$@")" + test_description="esyslog $(_print_args "$@")" EINFO_LOG=1 esyslog "$@" 2>/dev/null case $? in 0) @@ -308,7 +308,7 @@ test_is_identifier() { callback() { shift - test_description="is_identifier $(print_args "$@")" + test_description="is_identifier $(_print_args "$@")" is_identifier "$@" } @@ -333,7 +333,7 @@ test_is_int() { callback() { shift - test_description="is_int $(print_args "$@")" + test_description="is_int $(_print_args "$@")" is_int "$@" } @@ -353,7 +353,7 @@ test_is_visible() { callback() { shift - test_description="_is_visible $(print_args "$@")" + test_description="_is_visible $(_print_args "$@")" _is_visible "$@" } @@ -392,7 +392,7 @@ test_yesno() { callback() { shift - test_description="yesno $(print_args "$@")" + test_description="yesno $(_print_args "$@")" yesno "$@" }