summaryrefslogtreecommitdiff
path: root/test/run
blob: 1b2fd12a1a31b91173718c1df48b1cedf28bd5b4 (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
#!/bin/bash


# Print some helpful messages.
usage() {
    echo "Run bash-completion tests"
    echo
    echo "The 'tool' is determined automatically from filenames."
    echo "Unrecognized options are passed through to dejagnu by default."
    echo
    echo "Interesting options:"
    echo "  --tool_exec=    Test against a different bash executable."
    echo "  --debug         Create a dbg.log in the test directory with detailed expect match information."
    echo "  --debug-xtrace  Create an xtrace.log in the test directory with set -x output. Requires bash 4.1."
    echo
    echo "Example run: ./run unit/_get_cword.exp unit/compgen.exp"
}


# Try to set the tool variable; or fail if trying to set different values.
set_tool() {
    if [[ $tool ]]; then
        if [[ $tool != $1 ]]; then
            echo "Tool spec mismatch ('$tool' and '$1'). See --usage."
            exit 1
        fi
    else
        tool=$1
    fi
}


cd "${BASH_SOURCE[0]%/*}"


# Loop over the arguments.
args=()
while [[ $# > 0 ]]; do
    case "$1" in
        --help|--usage) usage; exit 1;;
        --debug-xtrace) args+=(OPT_BASH_XTRACE=1);;
        --tool=*) set_tool "${1#/--tool=}";;
        --tool) shift; set_tool "$1";;
        */completion/*.exp|*/unit/*.exp)
            arg=${1%/*}
            set_tool "${arg##*/}"
            args+=("${1##*/}")
            ;;
        *) args+=("$1")
    esac
    shift
done

[[ -z $tool ]] && { echo "Must specify tool somehow"; exit 1; }

runtest --outdir log --tool $tool "${args[@]}"