summaryrefslogtreecommitdiff
path: root/run-tests
blob: 4ee6f892a2e7be5c909626d7c64373524906c80f (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash -eu

# Author: w0rp <devw0rp@gmail.com>
#
# This script runs tests for the ALE project. The following options are
# accepted:
#
#            -v  Enable verbose output
# --neovim-only  Run tests only for NeoVim
#    --vim-only  Run tests only for Vim

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
CURRENT_IMAGE_ID=d5a1b5915b09
IMAGE=w0rp/ale
DOCKER_FLAGS=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$IMAGE")
EXIT=0

tests='test/*.vader test/*/*.vader test/*/*/*.vader test/*/*/*.vader'
verbose=0
quiet=0
run_neovim_tests=1
run_vim_tests=1
run_vint=1
run_custom_checks=1

while [ $# -ne 0 ]; do
    case $1 in
    -v)
        verbose=1
        shift
    ;;
    -q)
        quiet=1
        shift
    ;;
    --neovim-only)
        run_vim_tests=0
        run_vint=0
        run_custom_checks=0
        shift
    ;;
    --vim-only)
        run_neovim_tests=0
        run_vint=0
        run_custom_checks=0
    ;;
    --)
        shift
        break
    ;;
    -?*)
        echo "Invalid argument: $1" 1>&2
        exit 1
    ;;
    *)
        break
    ;;
    esac
done

# Allow tests to be passed as arguments.
if [ $# -ne 0 ]; then
    # This doesn't perfectly handle work splitting, but none of our files
    # have spaces in the names.
    tests="$*"
fi

docker images -q w0rp/ale | grep "^$CURRENT_IMAGE_ID" > /dev/null \
    || docker pull "$IMAGE"

function filter-vader-output() {
    # When verbose mode is off, suppress output until Vader starts.
    local start_output="$verbose"
    local filtered_data=''

    while read -r; do
        if ((!start_output)); then
            if [[ "$REPLY" = *'Starting Vader:'* ]]; then
                start_output=1
            else
                continue
            fi
        fi

        if ((quiet)); then
            if [[ "$REPLY" = *'Starting Vader:'* ]]; then
                filtered_data="$REPLY"
            elif [[ "$REPLY" = *'Success/Total'* ]]; then
                success="$(echo -n "$REPLY" | grep -o '[0-9]\+/' | head -n1 | cut -d/ -f1)"
                total="$(echo -n "$REPLY" | grep -o '/[0-9]\+' | head -n1 | cut -d/ -f2)"

                if [ "$success" -lt "$total" ]; then
                    echo "$filtered_data"
                    echo "$REPLY"
                fi

                filtered_data=''
            else
                filtered_data="$filtered_data"$'\n'"$REPLY"
            fi
        else
            echo "$REPLY"
        fi
    done
}

function color-vader-output() {
    while read -r; do
        if [[ "$REPLY" = *'[EXECUTE] (X)'* ]]; then
            echo -en "$RED"
        elif [[ "$REPLY" = *'[EXECUTE]'* ]] || [[ "$REPLY" = *'[  GIVEN]'* ]]; then
            echo -en "$NC"
        fi

        if [[ "$REPLY" = *'Success/Total'* ]]; then
            success="$(echo -n "$REPLY" | grep -o '[0-9]\+/' | head -n1 | cut -d/ -f1)"
            total="$(echo -n "$REPLY" | grep -o '/[0-9]\+' | head -n1 | cut -d/ -f2)"

            if [ "$success" -lt "$total" ]; then
                echo -en "$RED"
            else
                echo -en "$GREEN"
            fi

            echo "$REPLY"
            echo -en "$NC"
        else
            echo "$REPLY"
        fi
    done

    echo -en "$NC"
}

if ((run_neovim_tests)); then
    for vim in $(docker run --rm "$IMAGE" ls /vim-build/bin | grep '^neovim' ); do
        echo
        echo '========================================'
        echo "Running tests for $vim"
        echo '========================================'
        echo

        set -o pipefail
        docker run -it -e VADER_OUTPUT_FILE=/dev/stderr "${DOCKER_FLAGS[@]}" \
            "/vim-build/bin/$vim" -u test/vimrc \
            --headless "+Vader! $tests" | filter-vader-output | color-vader-output || EXIT=$?
        set +o pipefail
    done

    echo
fi

if ((run_vim_tests)); then
    for vim in $(docker run --rm "$IMAGE" ls /vim-build/bin | grep '^vim' ); do
        echo
        echo '========================================'
        echo "Running tests for $vim"
        echo '========================================'
        echo

        set -o pipefail
        docker run -a stderr "${DOCKER_FLAGS[@]}" \
            "/vim-build/bin/$vim" -u test/vimrc \
            "+Vader! $tests" 2>&1 | filter-vader-output | color-vader-output || EXIT=$?
        set +o pipefail
    done

    echo
fi

if ((run_vint)); then
    echo '========================================'
    echo 'Running Vint to lint our code'
    echo '========================================'
    echo 'Vint warnings/errors follow:'
    echo

    set -o pipefail
    docker run -a stdout "${DOCKER_FLAGS[@]}" vint -s . || EXIT=$?
    set +o pipefail
    echo
fi

if ((run_custom_checks)); then
    echo '========================================'
    echo 'Running custom checks'
    echo '========================================'
    echo 'Custom warnings/errors follow:'
    echo

    set -o pipefail
    docker run -a stdout "${DOCKER_FLAGS[@]}" ./custom-checks . || EXIT=$?
    set +o pipefail
    echo
fi

exit $EXIT