From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 27AFC431FAF for ; Wed, 28 Nov 2012 00:00:29 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TtG09iC90fNU for ; Wed, 28 Nov 2012 00:00:27 -0800 (PST) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id 74D63431FAE for ; Wed, 28 Nov 2012 00:00:27 -0800 (PST) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 5E7271000E5; Wed, 28 Nov 2012 10:00:25 +0200 (EET) From: Tomi Ollila To: Austin Clements , notmuch@notmuchmail.org Subject: Re: [PATCH] test: Use associative arrays to track external prereqs In-Reply-To: <1354078441-20788-1-git-send-email-amdragon@mit.edu> References: <1354078441-20788-1-git-send-email-amdragon@mit.edu> User-Agent: Notmuch/0.14+116~g29fcdb5 (http://notmuchmail.org) Emacs/24.2.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Nov 2012 08:00:29 -0000 On Wed, Nov 28 2012, Austin Clements wrote: > Previously, the test framework generated a variable name for each > external prereq as a poor man's associative array. Unfortunately, > prereqs names may not be legal variable names, leading to > unintelligible bash errors like > test_missing_external_prereq_emacsclient.emacs24_=t: command not found > > Using proper associative arrays to track prereqs, in addition to being > much cleaner than generating variable names and using grep to > carefully construct unique string lists, removes restrictions on > prereq names. > --- That looks good and something like I once attempted (at that time this would have make tests fail as this speeds up the script execution so much that smtp-dummy may not have time to start before it was used -- now that is taken care by smtp-dummy --background feature :) +1 Tomi > test/test-lib.sh | 24 ++++++++++++++---------- > 1 file changed, 14 insertions(+), 10 deletions(-) > > diff --git a/test/test-lib.sh b/test/test-lib.sh > index 77063a4..f169785 100644 > --- a/test/test-lib.sh > +++ b/test/test-lib.sh > @@ -625,18 +625,22 @@ test_have_prereq () { > esac > } > > +declare -A test_missing_external_prereq_ > +declare -A test_subtest_missing_external_prereq_ > + > # declare prerequisite for the given external binary > test_declare_external_prereq () { > binary="$1" > test "$#" = 2 && name=$2 || name="$binary(1)" > > - hash $binary 2>/dev/null || eval " > - test_missing_external_prereq_${binary}_=t > + if ! hash $binary 2>/dev/null; then > + test_missing_external_prereq_["${binary}"]=t > + eval " > $binary () { > - echo -n \"\$test_subtest_missing_external_prereqs_ \" | grep -qe \" $name \" || > - test_subtest_missing_external_prereqs_=\"\$test_subtest_missing_external_prereqs_ $name\" > + test_subtest_missing_external_prereq_[\"${name}\"]=t > false > }" > + fi > } > > # Explicitly require external prerequisite. Useful when binary is > @@ -644,7 +648,7 @@ $binary () { > # Returns success if dependency is available, failure otherwise. > test_require_external_prereq () { > binary="$1" > - if [ "$(eval echo -n \$test_missing_external_prereq_${binary}_)" = t ]; then > + if [[ ${test_missing_external_prereq_["${binary}"]} == t ]]; then > # dependency is missing, call the replacement function to note it > eval "$binary" > else > @@ -737,9 +741,9 @@ test_skip () { > } > > test_check_missing_external_prereqs_ () { > - if test -n "$test_subtest_missing_external_prereqs_"; then > - say_color skip >&1 "missing prerequisites:" > - echo "$test_subtest_missing_external_prereqs_" >&1 > + if [[ ${#test_subtest_missing_external_prereq_[@]} != 0 ]]; then > + say_color skip >&1 "missing prerequisites: " > + echo ${!test_subtest_missing_external_prereq_[@]} >&1 > test_report_skip_ "$@" > else > false > @@ -1022,7 +1026,7 @@ test_python() { > # most others as /usr/bin/python. So first try python2, and fallback to > # python if python2 doesn't exist. > cmd=python2 > - [[ "$test_missing_external_prereq_python2_" = t ]] && cmd=python > + [[ ${test_missing_external_prereq_[python2]} == t ]] && cmd=python > > (echo "import sys; _orig_stdout=sys.stdout; sys.stdout=open('OUTPUT', 'w')"; cat) \ > | $cmd - > @@ -1064,7 +1068,7 @@ test_reset_state_ () { > test -z "$test_init_done_" && test_init_ > > test_subtest_known_broken_= > - test_subtest_missing_external_prereqs_= > + test_subtest_missing_external_prereq_=() > } > > # called once before the first subtest > -- > 1.7.10.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch