summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-04-14 17:22:47 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-04-18 18:33:44 +0200
commit3c1f9fa15f745a8acecfef3f9f96211cdafb89ec (patch)
treebd27feaa02c54c2dd873ad3c82c7363f952be39b /tests
parent535483d4609e5a8057ccbf0a20cca8b289b97181 (diff)
Move test utilities to top-level test directory
Diffstat (limited to 'tests')
-rw-r--r--tests/utils.sh75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/utils.sh b/tests/utils.sh
new file mode 100644
index 00000000..8babfd21
--- /dev/null
+++ b/tests/utils.sh
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+
+#
+#
+# This file contains test utility functions which are used by the test scripts
+# for each binary.
+#
+#
+
+
+COLOR_OFF='\e[0m' # Text Reset
+RED='\e[0;31m' # Red
+YELLOW='\e[0;33m' # Yellow
+GREEN='\e[0;32m' # Green
+
+RUNTIME="/tmp"
+STORE="${RUNTIME}/store"
+
+out() {
+ [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${YELLOW}:: $*${COLOR_OFF}"
+}
+
+success() {
+ [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${GREEN}>> $*${COLOR_OFF}"
+}
+
+err() {
+ [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${RED}!! $*${COLOR_OFF}"
+}
+
+silent() {
+ DEBUG_OUTPUT_OFF=1 $*
+}
+
+imag-call-binary() {
+ local searchdir=$1; shift
+ local binary=$1; shift
+ [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; }
+ local bin=$(find $searchdir -iname $binary -type f -executable)
+ local flags="--debug --rtp $RUNTIME"
+ out "Calling '$bin $flags $*'"
+ $bin $flags $*
+}
+
+reset_store() {
+ rm -r "${STORE}"
+}
+
+call_test() {
+ out "-- TESTING: '$1' --"
+ $1
+ result=$?
+ if [[ -z "$DONT_RESET_STORE" ]]; then
+ out "Reseting store"
+ reset_store
+ out "Store reset done"
+ fi
+ [[ $result -eq 0 ]] || { err "-- FAILED: '$1'. Exiting."; exit 1; }
+ success "-- SUCCESS: '$1' --"
+}
+
+invoke_tests() {
+ out "Invoking tests."
+ if [[ ! -z "$INVOKE_TEST" ]]; then
+ out "Invoking only $INVOKE_TEST"
+ call_test "$INVOKE_TEST"
+ else
+ out "Invoking $*"
+ for t in $*; do
+ call_test "$t"
+ done
+ fi
+}
+
+