[PATCH v2] test: add "set -u" to test-lib.sh
authorTomi Ollila <tomi.ollila@iki.fi>
Tue, 7 Jun 2016 21:59:37 +0000 (00:59 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:22:01 +0000 (16:22 -0700)
19/9679a9dd7d66b68e85b28b227d6e5f63fcc468 [new file with mode: 0644]

diff --git a/19/9679a9dd7d66b68e85b28b227d6e5f63fcc468 b/19/9679a9dd7d66b68e85b28b227d6e5f63fcc468
new file mode 100644 (file)
index 0000000..93ef25a
--- /dev/null
@@ -0,0 +1,334 @@
+Return-Path: <too@guru-group.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 arlo.cworth.org (Postfix) with ESMTP id A40176DE0130\r
+ for <notmuch@notmuchmail.org>; Tue,  7 Jun 2016 15:00:07 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.243\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.243 tagged_above=-999 required=5 tests=[AWL=0.252, \r
+ HEADER_FROM_DIFFERENT_DOMAINS=0.001, T_RP_MATCHES_RCVD=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 7Ue-Jj8TytsH for <notmuch@notmuchmail.org>;\r
+ Tue,  7 Jun 2016 14:59:59 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by arlo.cworth.org (Postfix) with ESMTP id BB0E86DE00BF\r
+ for <notmuch@notmuchmail.org>; Tue,  7 Jun 2016 14:59:58 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+ id CF6B51001A6; Wed,  8 Jun 2016 00:59:38 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Cc: tomi.ollila@iki.fi\r
+Subject: [PATCH v2] test: add "set -u" to test-lib.sh\r
+Date: Wed,  8 Jun 2016 00:59:37 +0300\r
+Message-Id: <1465336777-31225-1-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 2.8.2\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 07 Jun 2016 22:00:07 -0000\r
+\r
+This prohibits unset variables to expand to empty strings.\r
+Without this e.g misspelled variables cause unintentional results.\r
+\r
+Now all the test variables are either initialized, or in case of\r
+optional arguments and user-provided environment variables (i.e.\r
+when it is not know whethet the variable is set) the form\r
+${variable-} is used.\r
+\r
+Two unusable lines (leftovers?) in T360-symbol-hiding.sh were removed;\r
+this was the only non-lib test code that needed to be edited for this\r
+change to work.\r
+---\r
+\r
+This is v2 of id:1441307395-2218-1-git-send-email-tomi.ollila@iki.fi\r
+\r
+(basically added ensuring that $TERM is set)\r
+\r
+because:\r
+\r
+id:1465043356-23420-2-git-send-email-david@tethera.net\r
+id:1465043356-23420-4-git-send-email-david@tethera.net\r
+\r
+(in *-4-* if [ "${NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK}" = "0" ]\r
+always returns false as $NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK\r
+is not defined, -> string comparison "" = "0" is false)\r
+\r
+I created this on top of current master (6a833a6e83) plus\r
+\r
+  id:1464212261-26892-1-git-send-email-tomi.ollila@iki.fi\r
+  id:1464212261-26892-2-git-send-email-tomi.ollila@iki.fi\r
+  id:1464439170-25978-1-git-send-email-tomi.ollila@iki.fi\r
+  id:1464439170-25978-2-git-send-email-tomi.ollila@iki.fi\r
+  id:1464439170-25978-3-git-send-email-tomi.ollila@iki.fi\r
+\r
+(so i could test this on 2 systems) -- but this applies on\r
+top of 6a833a6e83 (current master) too.\r
+\r
+ test/T360-symbol-hiding.sh |  3 ---\r
+ test/test-lib.sh           | 63 +++++++++++++++++++++++++++-------------------\r
+ 2 files changed, 37 insertions(+), 29 deletions(-)\r
+\r
+diff --git a/test/T360-symbol-hiding.sh b/test/T360-symbol-hiding.sh\r
+index b3dbb1b..3fec3b7 100755\r
+--- a/test/T360-symbol-hiding.sh\r
++++ b/test/T360-symbol-hiding.sh\r
+@@ -22,9 +22,6 @@ caught No backend database found at path 'CWD/nonexistent'\r
+ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
\r
+-test_begin_subtest 'checking output'\r
+-test_expect_equal "$result" "$output"\r
+-\r
+ test_begin_subtest 'comparing existing to exported symbols'\r
+ nm -P $TEST_DIRECTORY/../lib/libnotmuch.so | awk '$2 == "T" && $1 ~ "^notmuch" {print $1}' | sort | uniq > ACTUAL\r
+ sed -n 's/[[:blank:]]*\(notmuch_[^;]*\);/\1/p' $TEST_DIRECTORY/../notmuch.sym | sort | uniq > EXPORTED\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index 54c65b6..6cde453 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -23,6 +23,9 @@ if [ ${BASH_VERSINFO[0]} -lt 4 ]; then\r
+     exit 1\r
+ fi\r
\r
++# Exit immediately when attempting to expand unset variable.\r
++set -u\r
++\r
+ # Make sure echo builtin does not expand backslash-escape sequences by default.\r
+ shopt -u xpg_echo\r
\r
+@@ -32,7 +35,7 @@ this_test_bare=${this_test#T[0-9][0-9][0-9]-}\r
\r
+ # if --tee was passed, write the output not only to the terminal, but\r
+ # additionally to the file test-results/$BASENAME.out, too.\r
+-case "$GIT_TEST_TEE_STARTED, $* " in\r
++case "${GIT_TEST_TEE_STARTED-}, $* " in\r
+ done,*)\r
+       # do not redirect again\r
+       ;;\r
+@@ -53,7 +56,7 @@ BASH_XTRACEFD=7\r
+ export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'\r
\r
+ # Keep the original TERM for say_color and test_emacs\r
+-ORIGINAL_TERM=$TERM\r
++ORIGINAL_TERM=${TERM:-dumb}\r
\r
+ # dtach(1) provides more capable terminal environment to anything\r
+ # that requires more than dumb terminal...\r
+@@ -67,8 +70,8 @@ TZ=UTC\r
+ TERM=dumb\r
+ export LANG LC_ALL PAGER TERM TZ\r
+ GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\r
+-if [[ ( -n "$TEST_EMACS" && -z "$TEST_EMACSCLIENT" ) || \\r
+-      ( -z "$TEST_EMACS" && -n "$TEST_EMACSCLIENT" ) ]]; then\r
++if [[ ( -n "${TEST_EMACS-}" && -z "${TEST_EMACSCLIENT-}" ) || \\r
++      ( -z "${TEST_EMACS-}" && -n "${TEST_EMACSCLIENT-}" ) ]]; then\r
+     echo "error: must specify both or neither of TEST_EMACS and TEST_EMACSCLIENT" >&2\r
+     exit 1\r
+ fi\r
+@@ -110,7 +113,10 @@ _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"\r
+               tput setaf 1 >/dev/null 2>&1 &&\r
+               tput sgr0 >/dev/null 2>&1\r
+       ) &&\r
+-      color=t\r
++      color=t || color=\r
++\r
++debug= immediate= help= verbose= quiet=\r
++with_dashes= valgrind= verbose= root=\r
\r
+ while test "$#" -ne 0\r
+ do\r
+@@ -212,7 +218,7 @@ print_test_description ()\r
+       echo $this_test: "Testing ${test_description}"\r
+       test_description_printed=1\r
+ }\r
+-if [ -z "$NOTMUCH_TEST_QUIET" ]\r
++if [ -z "${NOTMUCH_TEST_QUIET=}" ]\r
+ then\r
+       print_test_description\r
+ fi\r
+@@ -345,6 +351,7 @@ remove_cr () {\r
+ gen_msg_cnt=0\r
+ gen_msg_filename=""\r
+ gen_msg_id=""\r
++test_subtest_name=\r
+ generate_message ()\r
+ {\r
+     # This is our (bash-specific) magic for doing named parameters\r
+@@ -352,48 +359,48 @@ generate_message ()\r
+     local additional_headers\r
\r
+     gen_msg_cnt=$((gen_msg_cnt + 1))\r
+-    if [ -z "${template[filename]}" ]; then\r
++    if [ -z "${template[filename]-}" ]; then\r
+       gen_msg_name="msg-$(printf "%03d" $gen_msg_cnt)"\r
+     else\r
+       gen_msg_name=${template[filename]}\r
+     fi\r
\r
+-    if [ -z "${template[id]}" ]; then\r
++    if [ -z "${template[id]-}" ]; then\r
+       gen_msg_id="${gen_msg_name%:2,*}@notmuch-test-suite"\r
+     else\r
+       gen_msg_id="${template[id]}"\r
+     fi\r
\r
+-    if [ -z "${template[dir]}" ]; then\r
++    if [ -z "${template[dir]-}" ]; then\r
+       gen_msg_filename="${MAIL_DIR}/$gen_msg_name"\r
+     else\r
+       gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"\r
+       mkdir -p "$(dirname "$gen_msg_filename")"\r
+     fi\r
\r
+-    if [ -z "${template[body]}" ]; then\r
++    if [ -z "${template[body]-}" ]; then\r
+       template[body]="This is just a test message (#${gen_msg_cnt})"\r
+     fi\r
\r
+-    if [ -z "${template[from]}" ]; then\r
++    if [ -z "${template[from]-}" ]; then\r
+       template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"\r
+     fi\r
\r
+-    if [ -z "${template[to]}" ]; then\r
++    if [ -z "${template[to]-}" ]; then\r
+       template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"\r
+     fi\r
\r
+-    if [ -z "${template[subject]}" ]; then\r
++    if [ -z "${template[subject]-}" ]; then\r
+       if [ -n "$test_subtest_name" ]; then\r
+           template[subject]="$test_subtest_name"\r
+       else\r
+           template[subject]="Test message #${gen_msg_cnt}"\r
+       fi\r
+-    elif [ "${template[subject]}" = "@FORCE_EMPTY" ]; then\r
++    elif [ "${template[subject]-}" = "@FORCE_EMPTY" ]; then\r
+       template[subject]=""\r
+     fi\r
\r
+-    if [ -z "${template[date]}" ]; then\r
++    if [ -z "${template[date]-}" ]; then\r
+       # we use decreasing timestamps here for historical reasons;\r
+       # the existing test suite when we converted to unique timestamps just\r
+       # happened to have signicantly fewer failures with that choice.\r
+@@ -406,42 +413,42 @@ generate_message ()\r
+     fi\r
\r
+     additional_headers=""\r
+-    if [ ! -z "${template[header]}" ]; then\r
++    if [ ! -z "${template[header]-}" ]; then\r
+       additional_headers="${template[header]}\r
+ ${additional_headers}"\r
+     fi\r
\r
+-    if [ ! -z "${template[reply-to]}" ]; then\r
++    if [ ! -z "${template[reply-to]-}" ]; then\r
+       additional_headers="Reply-To: ${template[reply-to]}\r
+ ${additional_headers}"\r
+     fi\r
\r
+-    if [ ! -z "${template[in-reply-to]}" ]; then\r
++    if [ ! -z "${template[in-reply-to]-}" ]; then\r
+       additional_headers="In-Reply-To: ${template[in-reply-to]}\r
+ ${additional_headers}"\r
+     fi\r
\r
+-    if [ ! -z "${template[cc]}" ]; then\r
++    if [ ! -z "${template[cc]-}" ]; then\r
+       additional_headers="Cc: ${template[cc]}\r
+ ${additional_headers}"\r
+     fi\r
\r
+-    if [ ! -z "${template[bcc]}" ]; then\r
++    if [ ! -z "${template[bcc]-}" ]; then\r
+       additional_headers="Bcc: ${template[bcc]}\r
+ ${additional_headers}"\r
+     fi\r
\r
+-    if [ ! -z "${template[references]}" ]; then\r
++    if [ ! -z "${template[references]-}" ]; then\r
+       additional_headers="References: ${template[references]}\r
+ ${additional_headers}"\r
+     fi\r
\r
+-    if [ ! -z "${template[content-type]}" ]; then\r
++    if [ ! -z "${template[content-type]-}" ]; then\r
+       additional_headers="Content-Type: ${template[content-type]}\r
+ ${additional_headers}"\r
+     fi\r
\r
+-    if [ ! -z "${template[content-transfer-encoding]}" ]; then\r
++    if [ ! -z "${template[content-transfer-encoding]-}" ]; then\r
+       additional_headers="Content-Transfer-Encoding: ${template[content-transfer-encoding]}\r
+ ${additional_headers}"\r
+     fi\r
+@@ -559,6 +566,7 @@ add_email_corpus ()\r
+     fi\r
+ }\r
\r
++inside_subtest=\r
+ test_begin_subtest ()\r
+ {\r
+     if [ -n "$inside_subtest" ]; then\r
+@@ -811,7 +819,7 @@ $binary () {\r
+ # Returns success if dependency is available, failure otherwise.\r
+ test_require_external_prereq () {\r
+       binary="$1"\r
+-      if [[ ${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
+@@ -882,6 +890,7 @@ test_run_ () {\r
+       return 0\r
+ }\r
\r
++: ${NOTMUCH_SKIP_TESTS=}\r
+ test_skip () {\r
+       test_count=$(($test_count+1))\r
+       to_skip=\r
+@@ -1146,6 +1155,7 @@ EOF\r
+       chmod a+x "$TMP_DIRECTORY/run_emacs"\r
+ }\r
\r
++EMACS_SERVER=\r
+ test_emacs () {\r
+       # test dependencies beforehand to avoid the waiting loop below\r
+       missing_dependencies=\r
+@@ -1246,6 +1256,7 @@ notmuch_counter_value () {\r
+       echo $count\r
+ }\r
\r
++test_init_done_=\r
+ test_reset_state_ () {\r
+       test -z "$test_init_done_" && test_init_\r
\r
+@@ -1345,8 +1356,8 @@ case $(uname -s) in\r
+       ;;\r
+ esac\r
\r
+-test -z "$NO_PERL" && test_set_prereq PERL\r
+-test -z "$NO_PYTHON" && test_set_prereq PYTHON\r
++test -z "${NO_PERL-}" && test_set_prereq PERL\r
++test -z "${NO_PYTHON-}" && test_set_prereq PYTHON\r
\r
+ # test whether the filesystem supports symbolic links\r
+ ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS\r
+-- \r
+2.8.2\r
+\r