summaryrefslogtreecommitdiffstats
path: root/tests/utils.sh
blob: 6fc23ad827dc7afc36252320a563c4397c3b669c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/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 $*
}

cat_entry() {
    cat ${STORE}/$1
}

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
}