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 4A649159C9B for ; Sun, 11 Aug 2024 10:11:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6431B2BC0A4; Sun, 11 Aug 2024 10:11:14 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.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 4D6D42BC0A4 for ; Sun, 11 Aug 2024 10:11:14 +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 3F07D34311E for ; Sun, 11 Aug 2024 10:11:13 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 2BB201EE5 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: <1723371058.f76dddb6a9e66ba3ffcb44822af0016d2b158b25.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: f76dddb6a9e66ba3ffcb44822af0016d2b158b25 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: a55100c2-31ba-4396-98ee-0f36dc72e146 X-Archives-Hash: a48ebf785f85fb97c22d65d3124bc5cc commit: f76dddb6a9e66ba3ffcb44822af0016d2b158b25 Author: Kerin Millar plushkava net> AuthorDate: Thu Aug 8 08:10:32 2024 +0000 Commit: Sam James gentoo org> CommitDate: Sun Aug 11 10:10:58 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=f76dddb6 test-functions: have three tests employ callback functions Convert test_local(), test_ebegin() and test_quote_args() so as to declare and use callbacks, just like the other tests. An appreciable code cleanup is the result. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> test-functions | 99 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/test-functions b/test-functions index 0b0e127..79c66a9 100755 --- a/test-functions +++ b/test-functions @@ -24,26 +24,27 @@ cleanup_tmpdir() { } test_local() { - ( - var=1 - f() { - local var=2 - g - test "${var}" = 3 || exit - } - g() { - test "${var}" = 2 || exit - var=3 - } - f - test "${var}" = 1 - ) 2>/dev/null - retval=$? - if [ "${retval}" -ne 0 ]; then - printf 'not ' - fi - printf 'ok %d - /bin/sh supports local\n' "$((testnum += 1))" - return "${retval}" + set -- eq 0 + + callback() { + test_description="/bin/sh supports local" + ( + var=1 + f() { + local var=2 + g + test "${var}" = 3 || exit + } + g() { + test "${var}" = 2 || exit + var=3 + } + f + test "${var}" = 1 + ) 2>/dev/null + } + + iterate_tests 2 "$@" } test_chdir() { @@ -104,21 +105,18 @@ test_die() { } test_ebegin() { - _eprint() { - shift - _ends_with_newline "$*" - } - - set -- "message" - ebegin "$1" - retval=$? + set -- eq 0 - if [ "${retval}" -ne 0 ]; then - printf 'not ' - fi - printf 'ok %d - ebegin %s (expecting terminating newline)\n' "$((testnum + 1))" "$1" + callback() ( + test_description="ebegin message (expecting terminating newline)" + _eprint() { + shift + _ends_with_newline "$*" + } + ebegin "message" + ) - return "${retval}" + iterate_tests 2 "$@" } test_edo() { @@ -926,25 +924,24 @@ test_contains_any() { } test_quote_args() { - local POSIXLY_CORRECT + set -- eq 0 - testnum=$((testnum + 1)) - retval=0 - i=0 - while [ "$(( i += 1 ))" -le 255 ]; do - fmt=$(printf '\\%o' "$i") - # shellcheck disable=2059 - str=$(printf "$fmt.") - quote_args "${str%.}" || break - done | cksum | { - read -r cksum _ - if [ "${cksum}" != "380900690" ]; then - printf 'not ' - retval=1 - fi - printf 'ok %d - quote_args output test (expected cksum 380900690, got %s)\n' "${testnum}" "${cksum}" - return "${retval}" + callback() { + local POSIXLY_CORRECT i + + test_description="quote_args output test (expecting cksum 380900690)" + i=0 + while [ "$((i += 1))" -le 255 ]; do + fmt=$(printf '\\%o' "$i") + # shellcheck disable=2059 + str=$(printf "$fmt.") + quote_args "${str%.}" || break + done \ + | cksum \ + | { read -r cksum _ && test "${cksum}" = "380900690"; } } + + iterate_tests 2 "$@" } test_assign() { @@ -1096,7 +1093,7 @@ elif ! GENFUN_MODULES="portage rc" . ./functions.sh; then else assign_tmpdir test_chdir || rc=1 - ( test_ebegin ) || rc=1; testnum=$((testnum + 1)) + test_ebegin || rc=1; testnum=$((testnum + 1)) test_is_older_than || rc=1 test_get_bootparam || rc=1 test_esyslog || rc=1