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.
2 DOCKER=${DOCKER:-docker}
4 # Author: w0rp <devw0rp@gmail.com>
6 # This script runs tests for the ALE project. Run `./run-tests --help` for
7 # options, or read the output below.
10 image=docker.io/denseanalysis/ale
12 # Create docker image tag based on Dockerfile contents
13 if [ -n "$(command -v md5)" ]; then
14 image_tag=$(md5 -q Dockerfile)
16 image_tag=$(md5sum Dockerfile | cut -d' ' -f1)
18 git_version=$(git describe --always --tags)
20 # Used in all test scripts for running the selected Docker image.
21 DOCKER_RUN_IMAGE="$image:$image_tag"
22 export DOCKER_RUN_IMAGE
24 tests='test/*.vader test/*/*.vader test/*/*/*.vader'
25 # These flags are forwarded to the script for running Vader tests.
35 while [ $# -ne 0 ]; do
103 run_neovim_07_tests=0
104 run_neovim_08_tests=0
111 run_neovim_07_tests=0
112 run_neovim_08_tests=0
119 run_neovim_07_tests=0
120 run_neovim_08_tests=1
124 echo 'Usage: ./run-tests [OPTION]... [FILE]...'
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'
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'
151 echo "Invalid argument: $1" 1>&2
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.
166 # Don't run other tools when targeting tests.
171 # Delete .swp files in the test directory, which cause Vim 8 to hang.
172 find test -name '*.swp' -delete
176 # Check if docker un image is available locally
177 has_image=$(docker images --quiet "${image}:${image_tag}" | wc -l)
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
187 echo "The DOCKER environment variable must be docker or podman, not ${DOCKER}"
192 if [[ $arch != x86_64 ]]; then
193 echo "Pre-built docker image is not available for architecture ${arch}"
196 echo "Downloading run image ${image}:${image_tag}"
197 docker pull "${image}:${image_tag}" &> /dev/null
200 if [ "$has_image" -eq 0 ] && ! download_image; then
201 echo "Building run image ${image}:${image_tag}"
203 build_args=( --build-arg GIT_VERSION="$git_version" )
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" )
212 "$DOCKER" build "${build_args[@]}" -t "${image}:${image_tag}" .
213 "$DOCKER" tag "${image}:${image_tag}" "${image}:latest"
215 if [[ -z "${DOCKER_HUB_USER:-}" || -z "${DOCKER_HUB_PASS:-}" ]]; then
216 echo "Docker Hub credentials not set, skip push"
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}"
223 echo "Docker run image ${image}:${image_tag} ready"
226 "$DOCKER" tag "${image}:${image_tag}" "${image}:latest"
228 output_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
230 trap '{ rm -rf "$output_dir"; }' EXIT
235 # Used for killing tests when you kill the script.
239 if [ -n "$pid_list" ]; then
240 for pid in $pid_list; do
246 # shellcheck disable=SC2046
247 docker kill $(docker ps -a -q --filter ancestor="$image" --format='{{.ID}}') &> /dev/null
249 if [ -d "$output_dir" ]; then
257 trap cancel_tests INT TERM
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 $!"
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 $!"
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 $!"
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 $!"
296 for pid in $pid_list; do
300 if ! wait "$pid"; then
305 # Hide output for things that passed if -q is set.
306 if [ "$quiet_flag" != '-q' ] || ((this_failed)); then
307 cat "$output_dir/$index"
312 echo 'Something went wrong!'
314 echo 'All tests passed!'