From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SLbeIjlXtl5mGAAA0tVLHw (envelope-from ) for ; Sat, 09 May 2020 07:09:45 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id eCFGIEZXtl4MWAAAbx9fmQ (envelope-from ) for ; Sat, 09 May 2020 07:09:58 +0000 Received: from arlo.cworth.org (arlo.cworth.org [50.126.95.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E8FB4940D58 for ; Sat, 9 May 2020 07:09:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id E0F7C6DE0AAB; Sat, 9 May 2020 00:09:52 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BqEqvt-qFXfH; Sat, 9 May 2020 00:09:52 -0700 (PDT) Received: from arlo.cworth.org (localhost [IPv6:::1]) by arlo.cworth.org (Postfix) with ESMTP id 777616DE0ABE; Sat, 9 May 2020 00:09:51 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 258546DE0ABE for ; Sat, 9 May 2020 00:09:49 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id J4tBAwh7EEWq for ; Sat, 9 May 2020 00:09:47 -0700 (PDT) Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [212.16.98.55]) by arlo.cworth.org (Postfix) with ESMTPS id 7288C6DE0AAB for ; Sat, 9 May 2020 00:09:45 -0700 (PDT) Received: from guru.guru-group.fi (unknown [IPv6:2a02:2380:1:9:5054:ff:feb7:a4bc]) (using TLSv1.2 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: too) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 163F51B00453; Sat, 9 May 2020 10:09:39 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1589008179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yYljMMenbxLLIegUxaMYJViQ/nopSFXl7dXP9admAgE=; b=IKQMT4f01oTQMQPQKgv0qFOPlDY4NQdKYZm66Uwfg1gSACpn9SBNj+8cO36OOZ1YkLihG7 nChulIkOX9zo+VdLzJppTSmOlv7qqjB4HHx/bnDMYjhLULKt3lutuclbyfjiZ3eWgaf7sA 8TWXUgobzvpQUwhzeGayuQEoa6aauHBEEBD4T0Rz3BezMYzBGMNB+Owj7FfyQMhsWdiYuw qaOc8MSQr8o8JFpMIGuIXN3OKpXnYI45+SjK4k6iYEqvXflP6DfdEW4bHorSYroOhnWj4g FnlAZqAqhiVh4SPEtXpg9upFsczuAEh1pTGifPNROCymJOhuVhNJgMINFig8Wg== From: Tomi Ollila To: Daniel Kahn Gillmor , Notmuch Mail Subject: Re: [PATCH 1/2 v2] test-lib: mark function variables as local In-Reply-To: <20200508232438.169867-1-dkg@fifthhorseman.net> References: <20200506235438.100518-1-dkg@fifthhorseman.net> <20200508232438.169867-1-dkg@fifthhorseman.net> User-Agent: Notmuch/0.28.3+84~g41389bb (https://notmuchmail.org) Emacs/26.3 (x86_64-pc-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1589008179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yYljMMenbxLLIegUxaMYJViQ/nopSFXl7dXP9admAgE=; b=ZjN43cW+1N6Byqzp8H6E389P/P51lBiwhQd97dZI7glN+sSdR6rtKvZY7ZCT5ZCINVXpSt L8qrkKAfver0ZhC5UJW9lOvsnvTpVoLmr5FUp1UZq6DrCX6DAmWVL4fdPR2YuvMVdX+bwN w1/J/1xniL0nln2uDyjonxkOfT66vru74uM5ckhLMRAUjnrRjIWkqQOf+uYDIdE9HC5IjP WMUObDOhz1vjrrQqoOiBjk4/0DeX00jQn5yifzwykquWMQrG3giW21bvXnsrZQGGeGcgBl ZcyTrCes6fvZTKAsOMibmzX+xrgNuKYgIm1oJqYdkh108VS38oRLpNVjFxKPew== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1589008179; a=rsa-sha256; cv=none; b=q0cn52ksV6cXaQY0hqPkzGRgT+1sXO4NZWpQU94U4rwIRHKjlwySBf4SmYRCyFn8FbDJjI eu7V9pHgJPWbGtGF7WiBecmPzVmLL/vdf9MSsLsehBJnmFw6OJNW7CqBCtfXdyKrKkPCc+ 1km0SyKaWOuLWtt6i5vUaJ56XnK6OOVZFYyLRmGKr+YvAPeqAjVe+20QBjfwwFZfXDa1Lj 3Df7UPICiwHwMjHE+VYUxwjF4zhe68lJSqvFTnWRBaGPM1R+xuF+unhR9QVSzViXHlwN0R xYXTmvwHg82WZSzHkc6uwsNfGt7gtY3tq3PxwPq51M2M5ZSekmzibRpSIFzniQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=too smtp.mailfrom=tomi.ollila@iki.fi X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: notmuch-bounces@notmuchmail.org Sender: "notmuch" X-Scanner: scn0 X-Spam-Score: 1.99 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=iki.fi header.s=lahtoruutu header.b=IKQMT4f0; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 50.126.95.6 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Scan-Result: default: False [1.99 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.45458935183819]; DWL_DNSWL_BLOCKED(0.00)[50.126.95.6:from]; IP_REPUTATION_HAM(0.00)[asn: 27017(-0.18), country: US(-0.00), ip: 50.126.95.6(-0.45)]; R_DKIM_REJECT(1.00)[iki.fi:s=lahtoruutu]; R_SPF_ALLOW(-0.20)[+a]; ARC_REJECT(2.00)[signature check failed: fail, {[1] = sig:iki.fi:reject}]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.50)[cached: notmuchmail.org]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[iki.fi:-]; MAILLIST(-0.20)[mailman]; RCVD_IN_DNSWL_FAIL(0.00)[50.126.95.6:server fail]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:27017, ipnet:50.126.64.0/18, country:US]; FROM_NEQ_ENVFROM(0.00)[tomi.ollila@iki.fi,notmuch-bounces@notmuchmail.org]; URIBL_BLOCKED(0.00)[fifthhorseman.net:email,test-lib.sh:url,notmuchmail.org:email,tldp.org:url]; FROM_HAS_DN(0.00)[]; SPF_REPUTATION_HAM(0.00)[-0.43554059521217]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[notmuch@notmuchmail.org]; DMARC_NA(0.00)[iki.fi]; HAS_LIST_UNSUB(-0.01)[]; RCVD_COUNT_SEVEN(0.00)[8]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: kZT88pHpcRpj On Fri, May 08 2020, Daniel Kahn Gillmor wrote: > Several functions in test/test-lib.sh used variable names that are > also used outside of those functions (e.g. $output and $expected are > used in many of the test scripts), but they are not expected to > communicate via those variables. > > We mark those variables "local" within test-lib.sh so that they do not > get clobbered when used outside test-lib. > > We also move the local variable declarations to beginning of each > function, to avoid weird gotchas with local variable declarations as > described in https://tldp.org/LDP/abs/html/localvar.html. LGTM. I have to tolerate 'we' (passive) as I seem to use those myself, too (although communicating a bit different thing...) =D Tomi > Signed-off-by: Daniel Kahn Gillmor > --- > test/test-lib.sh | 31 ++++++++++++++++++++++--------- > 1 file changed, 22 insertions(+), 9 deletions(-) > > diff --git a/test/test-lib.sh b/test/test-lib.sh > index 5c8eab7c..58972339 100644 > --- a/test/test-lib.sh > +++ b/test/test-lib.sh > @@ -109,7 +109,6 @@ unset ALTERNATE_EDITOR > > add_gnupg_home () > { > - local output > [ -e "${GNUPGHOME}/gpg.conf" ] && return > _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; } > at_exit_function _gnupg_exit > @@ -345,13 +344,14 @@ trap 'trap_signal' HUP INT TERM > # to the message and encrypting/signing. > emacs_deliver_message () > { > - local subject="$1" > - local body="$2" > + local subject body smtp_dummy_pid smtp_dummy_port > + subject="$1" > + body="$2" > shift 2 > # before we can send a message, we have to prepare the FCC maildir > mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp} > # eval'ing smtp-dummy --background will set smtp_dummy_pid and -_port > - local smtp_dummy_pid= smtp_dummy_port= > + smtp_dummy_pid= smtp_dummy_port= > eval `$TEST_DIRECTORY/smtp-dummy --background sent_message` > test -n "$smtp_dummy_pid" || return 1 > test -n "$smtp_dummy_port" || return 1 > @@ -391,13 +391,14 @@ emacs_deliver_message () > # new" after message delivery > emacs_fcc_message () > { > - local nmn_args='' > + local nmn_args subject body > + nmn_args='' > while [[ "$1" =~ ^-- ]]; do > nmn_args="$nmn_args $1" > shift > done > - local subject="$1" > - local body="$2" > + subject="$1" > + body="$2" > shift 2 > # before we can send a message, we have to prepare the FCC maildir > mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp} > @@ -427,6 +428,7 @@ emacs_fcc_message () > # number of messages. > add_email_corpus () > { > + local corpus > corpus=${1:-default} > > rm -rf ${MAIL_DIR} > @@ -457,6 +459,7 @@ test_begin_subtest () > # name. > test_expect_equal () > { > + local output expected testname > exec 1>&6 2>&7 # Restore stdout and stderr > if [ -z "$inside_subtest" ]; then > error "bug in the test script: test_expect_equal without test_begin_subtest" > @@ -483,6 +486,7 @@ test_expect_equal () > # Like test_expect_equal, but takes two filenames. > test_expect_equal_file () > { > + local file1 file2 testname basename1 basename2 > exec 1>&6 2>&7 # Restore stdout and stderr > if [ -z "$inside_subtest" ]; then > error "bug in the test script: test_expect_equal_file without test_begin_subtest" > @@ -512,10 +516,11 @@ test_expect_equal_file () > # canonicalized before diff'ing. If an argument cannot be parsed, it > # is used unchanged so that there's something to diff against. > test_expect_equal_json () { > + local script output expected > # The test suite forces LC_ALL=C, but this causes Python 3 to > # decode stdin as ASCII. We need to read JSON in UTF-8, so > # override Python's stdio encoding defaults. > - local script='import json, sys; json.dump(json.load(sys.stdin), sys.stdout, sort_keys=True, indent=4)' > + script='import json, sys; json.dump(json.load(sys.stdin), sys.stdout, sort_keys=True, indent=4)' > output=$(echo "$1" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c "$script" \ > || echo "$1") > expected=$(echo "$2" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c "$script" \ > @@ -540,6 +545,7 @@ test_sort_json () { > # read the source of test/json_check_nodes.py (or the output when > # invoking it without arguments) for an explanation of the syntax. > test_json_nodes () { > + local output > exec 1>&6 2>&7 # Restore stdout and stderr > if [ -z "$inside_subtest" ]; then > error "bug in the test script: test_json_eval without test_begin_subtest" > @@ -561,6 +567,7 @@ test_json_nodes () { > } > > test_emacs_expect_t () { > + local result > test "$#" = 1 || > error "bug in the test script: not 1 parameter to test_emacs_expect_t" > if [ -z "$inside_subtest" ]; then > @@ -653,7 +660,8 @@ notmuch_json_show_sanitize () > > notmuch_emacs_error_sanitize () > { > - local command=$1 > + local command > + command=$1 > shift > for file in "$@"; do > echo "=== $file ===" > @@ -717,6 +725,7 @@ declare -A test_subtest_missing_external_prereq_ > > # declare prerequisite for the given external binary > test_declare_external_prereq () { > + local binary > binary="$1" > test "$#" = 2 && name=$2 || name="$binary(1)" > > @@ -734,6 +743,7 @@ $binary () { > # called indirectly (e.g. from emacs). > # Returns success if dependency is available, failure otherwise. > test_require_external_prereq () { > + local binary > binary="$1" > if [[ ${test_missing_external_prereq_["${binary}"]} == t ]]; then > # dependency is missing, call the replacement function to note it > @@ -1075,6 +1085,7 @@ test_ruby() { > } > > test_C () { > + local exec_file test_file > exec_file="test${test_count}" > test_file="${exec_file}.c" > cat > ${test_file} > @@ -1086,6 +1097,7 @@ test_C () { > } > > make_shim () { > + local base_name test_file shim_file > base_name="$1" > test_file="${base_name}.c" > shim_file="${base_name}.so" > @@ -1094,6 +1106,7 @@ make_shim () { > } > > notmuch_with_shim () { > + local base_name shim_file > base_name="$1" > shift > shim_file="${base_name}.so" > -- > 2.26.2 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch