Re: [PATCH] test: Use associative arrays to track external prereqs
authorTomi Ollila <tomi.ollila@iki.fi>
Wed, 28 Nov 2012 08:00:25 +0000 (10:00 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:05 +0000 (09:51 -0800)
78/0d4c652c0013d456ee34db766691cd37a32298 [new file with mode: 0644]

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