tests: Use "bash strict mode"

I noticed in the static deltas tests, there were some tests that
should have been under `-o pipefail` to ensure we properly propagate
errors.

There were a few places where we were referencing undefined variables.

Overall, this is clearly a good idea IMO.
This commit is contained in:
Colin Walters 2016-01-27 11:44:10 -05:00
parent 3d2322db7a
commit 5ebe43859d
48 changed files with 59 additions and 66 deletions

View File

@ -16,7 +16,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
echo "1..10" echo "1..10"

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
$OSTREE checkout test2 checkout-test2 $OSTREE checkout test2 checkout-test2
echo "ok checkout" echo "ok checkout"

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
echo "1..48" echo "1..48"

View File

@ -33,11 +33,11 @@ cp -a ${SRCDIR}/gpghome ${test_tmpdir}
export TEST_GPG_KEYHOME=${test_tmpdir}/gpghome export TEST_GPG_KEYHOME=${test_tmpdir}/gpghome
export OSTREE_GPG_HOME=${test_tmpdir}/gpghome/trusted export OSTREE_GPG_HOME=${test_tmpdir}/gpghome/trusted
if test -n "${OT_TESTS_DEBUG}"; then if test -n "${OT_TESTS_DEBUG:-}"; then
set -x set -x
fi fi
if test -n "$OT_TESTS_VALGRIND"; then if test -n "${OT_TESTS_VALGRIND:-}"; then
CMD_PREFIX="env G_SLICE=always-malloc valgrind -q --leak-check=full --num-callers=30 --suppressions=${SRCDIR}/ostree-valgrind.supp" CMD_PREFIX="env G_SLICE=always-malloc valgrind -q --leak-check=full --num-callers=30 --suppressions=${SRCDIR}/ostree-valgrind.supp"
else else
CMD_PREFIX="env LD_PRELOAD=${SRCDIR}/libreaddir-rand.so" CMD_PREFIX="env LD_PRELOAD=${SRCDIR}/libreaddir-rand.so"
@ -139,8 +139,8 @@ setup_test_repository () {
setup_fake_remote_repo1() { setup_fake_remote_repo1() {
mode=$1 mode=$1
commit_opts=$2 commit_opts=${2:-}
args=$3 args=${3:-}
shift shift
oldpwd=`pwd` oldpwd=`pwd`
mkdir ostree-srv mkdir ostree-srv
@ -272,7 +272,7 @@ EOF
mkdir ${test_tmpdir}/httpd mkdir ${test_tmpdir}/httpd
cd httpd cd httpd
ln -s ${test_tmpdir} ostree ln -s ${test_tmpdir} ostree
${CMD_PREFIX} ostree trivial-httpd --autoexit --daemonize -p ${test_tmpdir}/httpd-port $args ${CMD_PREFIX} ostree trivial-httpd --autoexit --daemonize -p ${test_tmpdir}/httpd-port
port=$(cat ${test_tmpdir}/httpd-port) port=$(cat ${test_tmpdir}/httpd-port)
echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
cd ${oldpwd} cd ${oldpwd}
@ -280,15 +280,9 @@ EOF
os_repository_new_commit () os_repository_new_commit ()
{ {
boot_checksum_iteration=$1 boot_checksum_iteration=${1:-0}
content_iteration=$2 content_iteration=${2:-0}
echo "BOOT ITERATION: $boot_checksum_iteration" echo "BOOT ITERATION: $boot_checksum_iteration"
if test -z "$boot_checksum_iteration"; then
boot_checksum_iteration=0
fi
if test -z "$content_iteration"; then
content_iteration=0
fi
cd ${test_tmpdir}/osdata cd ${test_tmpdir}/osdata
rm boot/* rm boot/*
echo "new: a kernel ${boot_checksum_iteration}" > boot/vmlinuz-3.6.0 echo "new: a kernel ${boot_checksum_iteration}" > boot/vmlinuz-3.6.0

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
function repo_init() { function repo_init() {
cd ${test_tmpdir} cd ${test_tmpdir}

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh
@ -49,7 +49,6 @@ os_repository_new_commit "1"
bootcsum3=${bootcsum} bootcsum3=${bootcsum}
${CMD_PREFIX} ostree admin upgrade --os=testos ${CMD_PREFIX} ostree admin upgrade --os=testos
rev=${newrev}
newrev=$(${CMD_PREFIX} ostree --repo=sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime) newrev=$(${CMD_PREFIX} ostree --repo=sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime)
assert_not_streq ${rev} ${newrev} assert_not_streq ${rev} ${newrev}
assert_not_streq ${bootcsum1} ${bootcsum2} assert_not_streq ${bootcsum1} ${bootcsum2}

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -18,7 +18,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -18,7 +18,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -19,7 +19,7 @@
# See https://github.com/GNOME/ostree/pull/145 # See https://github.com/GNOME/ostree/pull/145
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -18,7 +18,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
echo "1..1" echo "1..1"

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
echo "1..1" echo "1..1"

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
echo "1..1" echo "1..1"

View File

@ -17,9 +17,9 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
if ! ${CMD_PREFIX} ostree --version | grep -q -e '\+gpgme'; then if ! ostree --version | grep -q -e '\+gpgme'; then
exit 77 exit 77
fi fi

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
echo "1..2" echo "1..2"

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -18,9 +18,9 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
if ! ${CMD_PREFIX} ostree --version | grep -q -e '\+gpgme'; then if ! ostree --version | grep -q -e '\+gpgme'; then
exit 77 exit 77
fi fi

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh
@ -45,7 +45,7 @@ test_recursive() {
if [ $? = 0 ] ; then if [ $? = 0 ] ; then
echo 1>&2 "missing subcommand but 0 exit status"; exit 1 echo 1>&2 "missing subcommand but 0 exit status"; exit 1
fi fi
set -e set -euo pipefail
# error message and usage goes to standard error # error message and usage goes to standard error
assert_file_has_content err "[Uu]sage" assert_file_has_content err "[Uu]sage"
assert_file_has_content err "$cmd" assert_file_has_content err "$cmd"

View File

@ -17,9 +17,9 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
if ! ${CMD_PREFIX} ostree --version | grep -q -e '\+libarchive'; then if ! ostree --version | grep -q -e '\+libarchive'; then
exit 77 exit 77
fi fi

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
echo "1..1" echo "1..1"

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh
@ -55,4 +55,4 @@ gjs --help >/dev/null 2>&1 || exit 77
gjs $(dirname $0)/corrupt-repo-ref.js ${repopath} main || true gjs $(dirname $0)/corrupt-repo-ref.js ${repopath} main || true
assert_file_has_content corrupted-status.txt 'Changed byte' assert_file_has_content corrupted-status.txt 'Changed byte'
do_corrupt_pull_test do_corrupt_pull_test
echo "ok corruption $iteration" echo "ok corruption"

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -18,7 +18,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
echo "1..1" echo "1..1"

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
echo "1..1" echo "1..1"

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
set -e set -euo pipefail
touch test-xattrs touch test-xattrs
if ! setfattr -n user.testvalue -v somevalue test-xattrs; then if ! setfattr -n user.testvalue -v somevalue test-xattrs; then