ale/run-tests

168 lines
4.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -e
set -u
# Author: w0rp <devw0rp@gmail.com>
#
# This script runs tests for the ALE project. Run `./run-tests --help` for
# options, or read the output below.
#
image=w0rp/ale
2018-07-03 18:21:58 +00:00
current_image_id=71553d0ab3e8
# Used in all test scripts for running the selected Docker image.
DOCKER_RUN_IMAGE="$image"
export DOCKER_RUN_IMAGE
tests='test/*.vader test/*/*.vader test/*/*/*.vader test/*/*/*.vader'
# These flags are forwarded to the script for running Vader tests.
verbose_flag=''
quiet_flag=''
run_neovim_02_tests=1
run_neovim_03_tests=1
run_vim_tests=1
run_linters=1
while [ $# -ne 0 ]; do
case $1 in
-v)
verbose_flag='-v'
shift
;;
-q)
quiet_flag='-q'
shift
;;
--neovim-only)
run_vim_tests=0
run_linters=0
shift
;;
--neovim-02-only)
run_neovim_03_tests=0
run_vim_tests=0
run_linters=0
shift
;;
--neovim-03-only)
run_neovim_02_tests=0
run_vim_tests=0
run_linters=0
shift
;;
--vim-only)
run_neovim_02_tests=0
run_neovim_03_tests=0
run_linters=0
shift
;;
--linters-only)
run_vim_tests=0
run_neovim_02_tests=0
run_neovim_03_tests=0
shift
;;
--help)
echo 'Usage: ./run-tests [OPTION]... [FILE]...'
echo
echo 'Filenames can be given as arguments to run a subset of tests.'
echo 'For example: ./run-tests test/test_ale_var.vader'
echo
echo 'Options:'
echo ' -v Enable verbose output'
echo ' -q Hide output for successful tests'
echo ' --neovim-only Run tests only for NeoVim 0.2 and 0.3'
echo ' --neovim-02-only Run tests only for NeoVim 0.2'
echo ' --neovim-03-only Run tests only for NeoVim 0.3'
echo ' --vim-only Run tests only for Vim'
echo ' --linters-only Run only Vint and custom checks'
echo ' --help Show this help text'
echo ' -- Stop parsing options after this'
exit 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="$*"
# Don't run other tools when targeting tests.
run_linters=0
fi
# Delete .swp files in the test directory, which cause Vim 8 to hang.
find test -name '*.swp' -delete
docker images -q w0rp/ale | grep "^$current_image_id" > /dev/null \
|| docker pull "$image"
2017-12-07 20:07:45 +00:00
output_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
trap '{ rm -rf "$output_dir"; }' EXIT
file_number=0
pid_list=''
for vim in $(docker run --rm "$DOCKER_RUN_IMAGE" ls /vim-build/bin | grep '^neovim\|^vim' ); do
if ( [[ $vim =~ ^vim ]] && ((run_vim_tests)) ) \
|| ( [[ $vim =~ ^neovim-v0.2 ]] && ((run_neovim_02_tests)) ) \
|| ( [[ $vim =~ ^neovim-v0.3 ]] && ((run_neovim_03_tests)) ); then
2017-12-07 20:07:45 +00:00
echo "Starting Vim: $vim..."
file_number=$((file_number+1))
test/script/run-vader-tests $quiet_flag $verbose_flag "$vim" "$tests" \
> "$output_dir/$file_number" 2>&1 &
pid_list="$pid_list $!"
fi
done
if ((run_linters)); then
2017-12-07 20:07:45 +00:00
echo "Starting Vint..."
file_number=$((file_number+1))
test/script/run-vint > "$output_dir/$file_number" 2>&1 &
pid_list="$pid_list $!"
2017-12-07 20:07:45 +00:00
echo "Starting Custom checks..."
file_number=$((file_number+1))
test/script/custom-checks &> "$output_dir/$file_number" 2>&1 &
pid_list="$pid_list $!"
fi
2017-12-07 20:07:45 +00:00
echo
failed=0
index=0
for pid in $pid_list; do
index=$((index+1))
if ! wait "$pid"; then
failed=1
fi
cat "$output_dir/$index"
done
if ((failed)); then
echo 'Something went wrong!'
else
echo 'All tests passed!'
fi
2017-12-07 20:07:45 +00:00
exit $failed