From f3619367a211d8d13977d7c554df45b469799e67 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 22 Apr 2015 14:54:33 +0100 Subject: [PATCH 1/4] Make sourcing of config.sh idempotent --- test/config.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/config.sh b/test/config.sh index c20f55a6..f1db670d 100644 --- a/test/config.sh +++ b/test/config.sh @@ -2,6 +2,13 @@ set -e +# Protect against being sourced multiple times to prevent +# overwriting assert.sh global state +if ! [ -z "$SOURCED_CONFIG_SH" ]; then + return +fi +SOURCED_CONFIG_SH=true + # these ought to match what is in Vagrantfile N_MACHINES=${N_MACHINES:-2} IP_PREFIX=${IP_PREFIX:-192.168.48} From 5e01021cba920448a2ff04220806e366f628e14c Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 22 Apr 2015 15:00:41 +0100 Subject: [PATCH 2/4] Avoid use of subshell in whitely/greyly --- test/config.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/config.sh b/test/config.sh index f1db670d..432a0a54 100644 --- a/test/config.sh +++ b/test/config.sh @@ -35,12 +35,21 @@ remote() { $@ > >(while read line; do echo -e "\e[0;34m$rem>\e[0m $line"; done) } +colourise() { + echo -ne '\e['$1'm' + shift + # It's important that we don't do this in a subshell, as some + # commands we execute need to modify global state + "$@" + echo -ne '\e[0m' +} + whitely() { - echo -e '\e[1;37m'`$@`'\e[0m' + colourise '1;37' "$@" } greyly () { - echo -e '\e[0;37m'`$@`'\e[0m' + colourise '0;37' "$@" } run_on() { From d850ea41a25078ac3320b0a1c62d39dfbb3a18c7 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 22 Apr 2015 15:02:08 +0100 Subject: [PATCH 3/4] Report overall status after running all suites --- test/config.sh | 8 ++++++++ test/run_all.sh | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/test/config.sh b/test/config.sh index 432a0a54..c67896ba 100644 --- a/test/config.sh +++ b/test/config.sh @@ -52,6 +52,14 @@ greyly () { colourise '0;37' "$@" } +redly() { + colourise '1;31' "$@" +} + +greenly() { + colourise '1;32' "$@" +} + run_on() { host=$1 shift 1 diff --git a/test/run_all.sh b/test/run_all.sh index f69977c1..5ea2755d 100755 --- a/test/run_all.sh +++ b/test/run_all.sh @@ -9,6 +9,21 @@ if ! bash ./sanity_check.sh; then fi whitely echo ...ok +# Modified version of _assert_cleanup from assert.sh that +# prints overall status +check_test_status() { + if [ $? -ne 0 ]; then + redly echo "---= !!!ABNORMAL TEST TERMINATION!!! =---" + elif [ $tests_suite_status -ne 0 ]; then + redly echo "---= !!!SUITE FAILURES - SEE ABOVE FOR DETAILS!!! =---" + exit $tests_suite_status + else + greenly echo "---= ALL SUITES PASSED =---" + fi +} +# Overwrite assert.sh _assert_cleanup trap with our own +trap check_test_status EXIT + for t in *_test.sh; do echo greyly echo "---= Running $t =---" From 6a06d0f95fb3d9639ed6b4dc602ebcb2ee4d7262 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 22 Apr 2015 15:37:50 +0100 Subject: [PATCH 4/4] Simplify ping tests to avoid set -e precipitated exit in failure case --- test/100_cross_hosts_test.sh | 3 +-- test/110_encryption_test.sh | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/100_cross_hosts_test.sh b/test/100_cross_hosts_test.sh index 13789bbd..faa445e5 100755 --- a/test/100_cross_hosts_test.sh +++ b/test/100_cross_hosts_test.sh @@ -18,7 +18,6 @@ weave_on $HOST2 launch $HOST1 weave_on $HOST2 run $C2/24 -t --name=c2 ubuntu weave_on $HOST1 run $C1/24 -t --name=c1 ubuntu -ok=$(exec_on $HOST1 c1 ping -q -c 4 $C2 >&2 && echo ok) -assert "echo $ok" "ok" +assert_raises "exec_on $HOST1 c1 ping -q -c 4 $C2" end_suite diff --git a/test/110_encryption_test.sh b/test/110_encryption_test.sh index 79831acf..2e604984 100755 --- a/test/110_encryption_test.sh +++ b/test/110_encryption_test.sh @@ -18,7 +18,6 @@ weave_on $HOST2 launch -password notverysecure $HOST1 weave_on $HOST2 run $C2/24 -t --name=c2 ubuntu weave_on $HOST1 run $C1/24 -t --name=c1 ubuntu -ok=$(exec_on $HOST1 c1 ping -q -c 4 $C2 >&2 && echo ok) -assert "echo $ok" "ok" +assert_raises "exec_on $HOST1 c1 ping -q -c 4 $C2" end_suite