test: make script exit (1) if it "fails" to source (.) a file

The files (test) scripts source (with builtin command `.`) provides
information which the scripts depend, and without the `source` to
succeed allowing script to continue may lead to dangerous situations
(e.g. rm -rf "${undefined_variable}"/*).

At the end of all source (.) lines construct ' || exit 1' was added;
In our case the script script will exit if it cannot find (or read) the
file to be sourced. Additionally script would also exits if the last
command of the sourced file exited nonzero.
This commit is contained in:
Tomi Ollila 2015-08-06 12:13:36 +03:00 committed by David Bremner
parent af3eba97fd
commit 02a2eeb427
71 changed files with 74 additions and 73 deletions

View file

@ -79,7 +79,7 @@ while getopts v:c:s: opt; do
done
shift `expr $OPTIND - 1`
. ./test-lib.sh
. ./test-lib.sh || exit 1
SHORT_CORPUS=$(basename ${CORPUS:-database})
DBNAME=${SHORT_CORPUS}${SUFFIX}

View file

@ -2,7 +2,7 @@
test_description='notmuch new'
. ./perf-test-lib.sh
. ./perf-test-lib.sh || exit 1
# ensure initial 'notmuch new' is run by memory_start
uncache_database

View file

@ -2,7 +2,7 @@
test_description='dump and restore'
. ./perf-test-lib.sh
. ./perf-test-lib.sh || exit 1
memory_start

View file

@ -2,7 +2,7 @@
test_description='notmuch new'
. ./perf-test-lib.sh
. ./perf-test-lib.sh || exit 1
uncache_database

View file

@ -2,7 +2,7 @@
test_description='dump and restore'
. ./perf-test-lib.sh
. ./perf-test-lib.sh || exit 1
time_start

View file

@ -2,7 +2,7 @@
test_description='tagging'
. ./perf-test-lib.sh
. ./perf-test-lib.sh || exit 1
time_start

View file

@ -1,4 +1,4 @@
. ./version.sh
. ./version.sh || exit 1
corpus_size=large
@ -25,7 +25,7 @@ do
echo "error: unknown performance test option '$1'" >&2; exit 1 ;;
esac
done
. ../test/test-lib-common.sh
. ../test/test-lib-common.sh || exit 1
set -e

View file

@ -138,7 +138,7 @@ Source 'test-lib.sh'
After assigning test_description, the test script should source
test-lib.sh like this:
. ./test-lib.sh
. ./test-lib.sh || exit 1
This test harness library does the following things:

View file

@ -14,7 +14,7 @@ then
exit 1
fi
. ./test-lib.sh
. ./test-lib.sh || exit 1
################################################################
# Test harness

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="online help"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_expect_success 'notmuch --help' 'notmuch --help'
test_expect_success 'notmuch help' 'notmuch help'

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch compact"'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_message '[subject]=One'
add_message '[subject]=Two'

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description='"notmuch config"'
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Get string value"
test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description='"notmuch setup"'
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Notmuch new without a config suggests notmuch setup"
output=$(notmuch --config=new-notmuch-config new 2>&1)

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch new" in several variations'
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "No new messages"
output=$(NOTMUCH_NEW --debug)

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch count" for messages and threads'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_email_corpus

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch insert"'
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_require_external_prereq gdb

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch search" in several variations'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_email_corpus

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='various settings for "notmuch search --output="'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_email_corpus

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch address" in several variants'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_email_corpus

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch search" by folder: and path: (with variations)'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_message '[dir]=bad' '[subject]="To the bone"'
add_message '[dir]=.' '[subject]="Top level"'

View file

@ -18,7 +18,7 @@
# id:3wd4o8wa7fx.fsf@testarossa.amd.com
test_description='that notmuch does not overlap term positions'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_message '[to]="a@b.c, x@y.z"'

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='messages with unquoted . in name'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_message \
'[from]="Some.Name for Someone <bugs@quoting.com>"' \

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch search" --offset and --limit parameters'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_email_corpus

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch search, count and show" with excludes in several variations'
. ./test-lib.sh
. ./test-lib.sh || exit 1
# Generates a thread consisting of a top level message and 'length'
# replies. The subject of the top message 'subject: top message"

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='"notmuch tag"'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_message '[subject]=One'
add_message '[subject]=Two'

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="--format=json output"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Show message: json"
add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"json-show-message\""

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="--format=sexp output"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Show message: sexp"
add_message "[subject]=\"sexp-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"sexp-show-message\""

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="--format=text output"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Show message: text"
add_message "[subject]=\"text-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"text-show-message\""

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="output of multipart message"
. ./test-lib.sh
. ./test-lib.sh || exit 1
cat <<EOF > embedded_message
From: Carl Worth <cworth@cworth.org>

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="naming of threads with changing subject"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Initial thread name (oldest-first search)"
add_message '[subject]="thread-naming: Initial thread subject"' \

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="naming of authors with unusual addresses"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Add author with empty quoted real name"
add_message '[subject]="author-naming: Initial thread subject"' \

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description='notmuch show --format=raw'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_message
add_message

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="\"notmuch reply\" in several variations"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Basic reply"
add_message '[from]="Sender <sender@example.com>"' \

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="\"notmuch reply --reply-to=sender\" in several variations"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Basic reply-to-sender"
add_message '[from]="Sender <sender@example.com>"' \

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="\"notmuch dump\" and \"notmuch restore\""
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_email_corpus

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="handling of uuencoded data"
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
'[body]="This message is used to ensure that notmuch correctly handles a

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="threading when messages received out of order"
. ./test-lib.sh
. ./test-lib.sh || exit 1
# Generate all single-root four message thread structures. We'll use
# this for multiple tests below.

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="author reordering;"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Adding parent message"
generate_message [body]=findme [id]=new-parent-id [subject]=author-reorder-threadtest '[from]="User <user@example.com>"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="From line heuristics (with multiple configured addresses)"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Magic from guessing (nothing to go on)"
add_message '[from]="Sender <sender@example.com>"' \

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="messages with ridiculously-long message IDs"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Referencing long ID before adding"
generate_message '[subject]="Reference of ridiculously-long message ID"' \

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="encoding issues"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Message with text of unknown charset"
add_message '[content-type]="text/plain; charset=unknown-8bit"' \

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="emacs interface"
. ./test-lib.sh
. ./test-lib.sh || exit 1
EXPECTED=$TEST_DIRECTORY/emacs.expected-output

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="Emacs with large search results buffer"
. ./test-lib.sh
. ./test-lib.sh || exit 1
x=xxxxxxxxxx # 10
x=$x$x$x$x$x$x$x$x$x$x # 100

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="emacs: mail subject to filename"
. ./test-lib.sh
. ./test-lib.sh || exit 1
# emacs server can't be started in a child process with $(test_emacs ...)
test_emacs '(ignore)' > /dev/null

View file

@ -2,7 +2,7 @@
test_description="maildir synchronization"
. ./test-lib.sh
. ./test-lib.sh || exit 1
# Create the expected maildir structure
mkdir $MAIL_DIR/cur

View file

@ -5,7 +5,7 @@
# - verification of signatures from expired/revoked keys
test_description='PGP/MIME signature verification and decryption'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_gnupg_home ()
{

View file

@ -9,7 +9,7 @@
test_description='exception symbol hiding'
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest 'running test' run_test
mkdir -p ${PWD}/fakedb/.notmuch

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='folder tags removed and added through file renames remain consistent'
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "No new messages"
output=$(NOTMUCH_NEW)

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='atomicity'
. ./test-lib.sh
. ./test-lib.sh || exit 1
# This script tests the effects of killing and restarting "notmuch
# new" at arbitrary points. If notmuch new is properly atomic, the

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="python bindings"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_require_external_prereq ${NOTMUCH_PYTHON}

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="ruby bindings"
. ./test-lib.sh
. ./test-lib.sh || exit 1
if [ "${NOTMUCH_HAVE_RUBY_DEV}" = "0" ]; then
test_subtest_missing_external_prereq_["ruby development files"]=t

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='hooks'
. ./test-lib.sh
. ./test-lib.sh || exit 1
HOOK_DIR=${MAIL_DIR}/.notmuch/hooks

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="argument parsing"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "sanity check"
$TEST_DIRECTORY/arg-test pos1 --keyword=one --string=foo pos2 --int=7 --flag=one --flag=three > OUTPUT

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="emacs test function sanity"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "emacs test function sanity"
test_emacs_expect_t 't'

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="emacs address cleaning"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "notmuch-test-address-clean part 1"
test_emacs_expect_t '(notmuch-test-address-cleaning-1)'

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="emacs notmuch-hello view"
. ./test-lib.sh
. ./test-lib.sh || exit 1
EXPECTED=$TEST_DIRECTORY/emacs.expected-output

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="emacs notmuch-show view"
. ./test-lib.sh
. ./test-lib.sh || exit 1
EXPECTED=$TEST_DIRECTORY/emacs-show.expected-output

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="emacs notmuch-show charset handling"
. ./test-lib.sh
. ./test-lib.sh || exit 1
UTF8_YEN=$'\xef\xbf\xa5'

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="emacs tree view interface"
. test-lib.sh
. ./test-lib.sh || exit 1
EXPECTED=$TEST_DIRECTORY/tree.expected-output

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description='messages with missing headers'
. ./test-lib.sh
. ./test-lib.sh || exit 1
# Notmuch requires at least one of from, subject, or to or it will
# ignore the file. Generate two messages so that together they cover

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="hex encoding and decoding"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "round trip"
find $TEST_DIRECTORY/corpus -type f -print | sort | xargs cat > EXPECTED

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="date/time parser module"
. ./test-lib.sh
. ./test-lib.sh || exit 1
# Sanity/smoke tests for the date/time parser independent of notmuch

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
test_description="date:since..until queries"
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_email_corpus

View file

@ -9,7 +9,7 @@ test_description='test of proper handling of in-reply-to and references headers'
# database is constructed properly, even in the presence of
# non-RFC-compliant headers'
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "Use References when In-Reply-To is broken"
add_message '[id]="foo@one.com"' \

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description='"notmuch show"'
. ./test-lib.sh
. ./test-lib.sh || exit 1
add_email_corpus

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="database upgrade"
. ./test-lib.sh
. ./test-lib.sh || exit 1
dbtarball=database-v1.tar.xz

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="database version and feature compatibility"
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_begin_subtest "future database versions abort open"
${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 9999 ""

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
test_description="error reporting for library"
. ./test-lib.sh
. ./test-lib.sh || exit 1
backup_database () {
rm -rf notmuch-dir-backup

View file

@ -40,7 +40,7 @@ TEST_DIRECTORY=$(pwd)
notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"`
# configure output
. $notmuch_path/sh.config
. $notmuch_path/sh.config || exit 1
if test -n "$valgrind"
then

View file

@ -96,7 +96,8 @@ _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"
# test_description='Description of this test...
# This test checks if command xyzzy does the right thing...
# '
# . ./test-lib.sh
# . ./test-lib.sh || exit 1
[ "x$ORIGINAL_TERM" != "xdumb" ] && (
TERM=$ORIGINAL_TERM &&
export TERM &&
@ -1223,7 +1224,7 @@ test_init_ () {
}
. ./test-lib-common.sh
. ./test-lib-common.sh || exit 1
emacs_generate_script

View file

@ -2,7 +2,7 @@
test_description='the verbosity options of the test framework itself.'
. ./test-lib.sh
. ./test-lib.sh || exit 1
test_expect_success 'print something in test_expect_success and pass' '
echo "hello stdout" &&