]> git.madduck.net Git - etc/vim.git/blob - run-tests

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / run-tests
1 #!/usr/bin/env bash
2 DOCKER=${DOCKER:-docker}
3 export DOCKER
4 # Author: w0rp <devw0rp@gmail.com>
5 #
6 # This script runs tests for the ALE project. Run `./run-tests --help` for
7 # options, or read the output below.
8 #
9
10 image=docker.io/denseanalysis/ale
11
12 # Create docker image tag based on Dockerfile contents
13 if [ -n "$(command -v md5)" ]; then
14     image_tag=$(md5 -q Dockerfile)
15 else
16     image_tag=$(md5sum Dockerfile | cut -d' ' -f1)
17 fi
18 git_version=$(git describe --always --tags)
19
20 # Used in all test scripts for running the selected Docker image.
21 DOCKER_RUN_IMAGE="$image:$image_tag"
22 export DOCKER_RUN_IMAGE
23
24 tests='test/*.vader test/*/*.vader test/*/*/*.vader'
25 # These flags are forwarded to the script for running Vader tests.
26 verbose_flag=''
27 quiet_flag=''
28 run_neovim_07_tests=1
29 run_neovim_08_tests=1
30 run_vim_80_tests=1
31 run_vim_90_tests=1
32 run_lua_tests=1
33 run_linters=1
34
35 while [ $# -ne 0 ]; do
36     case $1 in
37     -v)
38         verbose_flag='-v'
39         shift
40     ;;
41     -q)
42         quiet_flag='-q'
43         shift
44     ;;
45     --build-image)
46         run_vim_80_tests=0
47         run_vim_90_tests=0
48         run_neovim_07_tests=0
49         run_neovim_08_tests=0
50         run_lua_tests=0
51         run_linters=0
52         shift
53     ;;
54     --neovim-only)
55         run_vim_80_tests=0
56         run_vim_90_tests=0
57         run_lua_tests=0
58         run_linters=0
59         shift
60     ;;
61     --neovim-07-only)
62         run_neovim_08_tests=0
63         run_vim_80_tests=0
64         run_vim_90_tests=0
65         run_lua_tests=0
66         run_linters=0
67         shift
68     ;;
69     --neovim-08-only)
70         run_neovim_07_tests=0
71         run_vim_80_tests=0
72         run_vim_90_tests=0
73         run_lua_tests=0
74         run_linters=0
75         shift
76     ;;
77     --vim-only)
78         run_neovim_07_tests=0
79         run_neovim_08_tests=0
80         run_lua_tests=0
81         run_linters=0
82         shift
83     ;;
84     --vim-80-only)
85         run_neovim_07_tests=0
86         run_neovim_08_tests=0
87         run_vim_90_tests=0
88         run_lua_tests=0
89         run_linters=0
90         shift
91     ;;
92     --vim-90-only)
93         run_neovim_07_tests=0
94         run_neovim_08_tests=0
95         run_vim_80_tests=0
96         run_lua_tests=0
97         run_linters=0
98         shift
99     ;;
100     --linters-only)
101         run_vim_80_tests=0
102         run_vim_90_tests=0
103         run_neovim_07_tests=0
104         run_neovim_08_tests=0
105         run_lua_tests=0
106         shift
107     ;;
108     --lua-only)
109         run_vim_80_tests=0
110         run_vim_90_tests=0
111         run_neovim_07_tests=0
112         run_neovim_08_tests=0
113         run_linters=0
114         shift
115     ;;
116     --fast)
117         run_vim_80_tests=0
118         run_vim_90_tests=0
119         run_neovim_07_tests=0
120         run_neovim_08_tests=1
121         shift
122     ;;
123     --help)
124         echo 'Usage: ./run-tests [OPTION]... [FILE]...'
125         echo
126         echo 'Filenames can be given as arguments to run a subset of tests.'
127         echo 'For example: ./run-tests test/test_ale_var.vader'
128         echo
129         echo 'Options:'
130         echo '  -v                Enable verbose output'
131         echo '  -q                Hide output for successful tests'
132         echo '  --build-image     Run docker image build only.'
133         echo '  --neovim-only     Run tests only for Neovim'
134         echo '  --neovim-07-only  Run tests only for Neovim 0.7'
135         echo '  --neovim-08-only  Run tests only for Neovim 0.8'
136         echo '  --vim-only        Run tests only for Vim'
137         echo '  --vim-80-only     Run tests only for Vim 8.2'
138         echo '  --vim-90-only     Run tests only for Vim 9.0'
139         echo '  --lua-only        Run only Lua tests'
140         echo '  --linters-only    Run only Vint and custom checks'
141         echo '  --fast            Run only the fastest Vim and custom checks'
142         echo '  --help            Show this help text'
143         echo '  --                Stop parsing options after this'
144         exit 0
145     ;;
146     --)
147         shift
148         break
149     ;;
150     -?*)
151         echo "Invalid argument: $1" 1>&2
152         exit 1
153     ;;
154     *)
155         break
156     ;;
157     esac
158 done
159
160 # Allow tests to be passed as arguments.
161 if [ $# -ne 0 ]; then
162     # This doesn't perfectly handle work splitting, but none of our files
163     # have spaces in the names.
164     tests="$*"
165
166     # Don't run other tools when targeting tests.
167     run_linters=0
168     run_lua_tests=0
169 fi
170
171 # Delete .swp files in the test directory, which cause Vim 8 to hang.
172 find test -name '*.swp' -delete
173
174 set -eu
175
176 # Check if docker un image is available locally
177 has_image=$(docker images --quiet "${image}:${image_tag}" | wc -l)
178
179 if [[ "$DOCKER" == docker ]]; then
180   arch=$(docker info -f '{{ .Architecture }}')
181 elif [[ "$DOCKER" == podman ]]; then
182   arch=$(podman info -f '{{ .Host.Arch }}')
183   if [[ "$arch" == "amd64" ]]; then
184     arch="x86_64"
185   fi
186 else
187   echo "The DOCKER environment variable must be docker or podman, not ${DOCKER}"
188   exit 1
189 fi
190
191 download_image() {
192   if [[ $arch != x86_64 ]]; then
193     echo "Pre-built docker image is not available for architecture ${arch}"
194     return 1
195   fi
196   echo "Downloading run image ${image}:${image_tag}"
197   docker pull "${image}:${image_tag}" &> /dev/null
198 }
199
200 if [ "$has_image" -eq 0 ] && ! download_image; then
201   echo "Building run image ${image}:${image_tag}"
202
203   build_args=( --build-arg GIT_VERSION="$git_version" )
204
205   if [[ $arch != x86_64 ]]; then
206     echo "Building testbed/vim:24 for $arch"
207     testbed_vim_ref=902917c4caa50db2f2e80009b839605602f9f014
208     "$DOCKER" build -t "testbed/vim:$testbed_vim_ref" "https://github.com/Vimjas/vim-testbed.git#$testbed_vim_ref"
209     build_args+=( --build-arg TESTBED_VIM_VERSION="$testbed_vim_ref" )
210   fi
211
212   "$DOCKER" build "${build_args[@]}" -t "${image}:${image_tag}" .
213   "$DOCKER" tag "${image}:${image_tag}" "${image}:latest"
214
215   if [[ -z "${DOCKER_HUB_USER:-}" || -z "${DOCKER_HUB_PASS:-}" ]]; then
216     echo "Docker Hub credentials not set, skip push"
217   else
218     echo "Push ${image}:${image_tag} to Docker Hub"
219     echo "$DOCKER_HUB_PASS" | docker login -u "$DOCKER_HUB_USER" --password-stdin
220     docker push "${image}:${image_tag}"
221   fi
222 else
223   echo "Docker run image ${image}:${image_tag} ready"
224 fi
225
226 "$DOCKER" tag "${image}:${image_tag}" "${image}:latest"
227
228 output_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
229
230 trap '{ rm -rf "$output_dir"; }' EXIT
231
232 file_number=0
233 pid_list=''
234
235 # Used for killing tests when you kill the script.
236 cancel_tests() {
237     set +e
238
239     if [ -n "$pid_list" ]; then
240         for pid in $pid_list; do
241             kill "$pid"
242             wait "$pid"
243         done
244     fi
245
246     # shellcheck disable=SC2046
247     docker kill $(docker ps -a -q --filter ancestor="$image" --format='{{.ID}}') &> /dev/null
248
249     if [ -d "$output_dir" ]; then
250         rm -rf "$output_dir"
251     fi
252
253     echo
254     exit 1
255 }
256
257 trap cancel_tests INT TERM
258
259 for vim in $("$DOCKER" run --rm "$DOCKER_RUN_IMAGE" ls /vim-build/bin | grep '^neovim\|^vim' ); do
260     if ( [[ $vim =~ ^vim-v8.0 ]] && ((run_vim_80_tests)) ) \
261     || ( [[ $vim =~ ^vim-v9.0 ]] && ((run_vim_90_tests)) ) \
262     || ( [[ $vim =~ ^neovim-v0.7 ]] && ((run_neovim_07_tests)) ) \
263     || ( [[ $vim =~ ^neovim-v0.8 ]] && ((run_neovim_08_tests)) ); then
264         echo "Starting Vim: $vim..."
265         file_number=$((file_number+1))
266         test/script/run-vader-tests $quiet_flag $verbose_flag "$vim" "$tests" \
267             > "$output_dir/$file_number" 2>&1 &
268         pid_list="$pid_list $!"
269     fi
270 done
271
272 if ((run_lua_tests)); then
273     echo "Starting Lua tests..."
274     file_number=$((file_number+1))
275     test/script/run-lua-tests $quiet_flag > "$output_dir/$file_number" 2>&1 &
276     pid_list="$pid_list $!"
277 fi
278
279 if ((run_linters)); then
280     echo "Starting Vint..."
281     file_number=$((file_number+1))
282     test/script/run-vint > "$output_dir/$file_number" 2>&1 &
283     pid_list="$pid_list $!"
284
285     echo "Starting Custom checks..."
286     file_number=$((file_number+1))
287     test/script/custom-checks &> "$output_dir/$file_number" 2>&1 &
288     pid_list="$pid_list $!"
289 fi
290
291 echo
292
293 failed=0
294 index=0
295
296 for pid in $pid_list; do
297     this_failed=0
298     index=$((index+1))
299
300     if ! wait "$pid"; then
301         failed=1
302         this_failed=1
303     fi
304
305     # Hide output for things that passed if -q is set.
306     if [ "$quiet_flag" != '-q' ] || ((this_failed)); then
307         cat "$output_dir/$index"
308     fi
309 done
310
311 if ((failed)); then
312     echo 'Something went wrong!'
313 else
314     echo 'All tests passed!'
315 fi
316
317 exit $failed