2018-05-01 12:18:03 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
2017-05-12 19:38:52 +00:00
|
|
|
|
|
|
|
# Author: w0rp <devw0rp@gmail.com>
|
|
|
|
#
|
2018-07-01 18:56:17 +00:00
|
|
|
# This script runs tests for the ALE project. Run `./run-tests --help` for
|
|
|
|
# options, or read the output below.
|
2017-05-12 19:38:52 +00:00
|
|
|
#
|
|
|
|
|
2021-01-27 19:52:24 +00:00
|
|
|
image=denseanalysis/ale
|
|
|
|
|
|
|
|
# Create docker image tag based on Dockerfile contents
|
|
|
|
image_tag=$(md5sum Dockerfile | cut -d' ' -f1)
|
|
|
|
git_version=$(git describe --always --tags)
|
2018-06-28 12:53:49 +00:00
|
|
|
|
|
|
|
# Used in all test scripts for running the selected Docker image.
|
2018-07-04 08:36:37 +00:00
|
|
|
DOCKER_RUN_IMAGE="$image"
|
2018-06-28 12:53:49 +00:00
|
|
|
export DOCKER_RUN_IMAGE
|
2017-05-12 19:38:52 +00:00
|
|
|
|
|
|
|
tests='test/*.vader test/*/*.vader test/*/*/*.vader test/*/*/*.vader'
|
2017-12-01 17:50:19 +00:00
|
|
|
# These flags are forwarded to the script for running Vader tests.
|
|
|
|
verbose_flag=''
|
|
|
|
quiet_flag=''
|
2018-06-28 12:53:49 +00:00
|
|
|
run_neovim_02_tests=1
|
2021-01-27 19:52:24 +00:00
|
|
|
run_neovim_04_tests=1
|
2018-07-23 19:41:06 +00:00
|
|
|
run_vim_80_tests=1
|
2021-01-27 19:52:24 +00:00
|
|
|
run_vim_82_tests=1
|
2018-07-01 11:06:36 +00:00
|
|
|
run_linters=1
|
2017-05-12 19:38:52 +00:00
|
|
|
|
|
|
|
while [ $# -ne 0 ]; do
|
|
|
|
case $1 in
|
|
|
|
-v)
|
2017-12-01 17:50:19 +00:00
|
|
|
verbose_flag='-v'
|
2017-05-12 19:38:52 +00:00
|
|
|
shift
|
|
|
|
;;
|
2017-05-20 18:02:01 +00:00
|
|
|
-q)
|
2017-12-01 17:50:19 +00:00
|
|
|
quiet_flag='-q'
|
2017-05-20 18:02:01 +00:00
|
|
|
shift
|
|
|
|
;;
|
2021-01-27 19:52:24 +00:00
|
|
|
--build-image)
|
|
|
|
run_vim_80_tests=0
|
|
|
|
run_vim_82_tests=0
|
|
|
|
run_neovim_02_tests=0
|
|
|
|
run_neovim_04_tests=0
|
|
|
|
run_linters=0
|
|
|
|
shift
|
|
|
|
;;
|
2017-05-12 19:38:52 +00:00
|
|
|
--neovim-only)
|
2018-07-23 19:41:06 +00:00
|
|
|
run_vim_80_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_vim_82_tests=0
|
2018-07-01 11:06:36 +00:00
|
|
|
run_linters=0
|
2017-05-12 19:38:52 +00:00
|
|
|
shift
|
|
|
|
;;
|
2018-06-28 12:53:49 +00:00
|
|
|
--neovim-02-only)
|
2021-01-27 19:52:24 +00:00
|
|
|
run_neovim_04_tests=0
|
2018-07-23 19:41:06 +00:00
|
|
|
run_vim_80_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_vim_82_tests=0
|
2018-07-01 11:06:36 +00:00
|
|
|
run_linters=0
|
2018-06-28 12:53:49 +00:00
|
|
|
shift
|
|
|
|
;;
|
2021-01-27 19:52:24 +00:00
|
|
|
--neovim-04-only)
|
2018-06-28 12:53:49 +00:00
|
|
|
run_neovim_02_tests=0
|
2018-07-23 19:41:06 +00:00
|
|
|
run_vim_80_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_vim_82_tests=0
|
2018-07-01 11:06:36 +00:00
|
|
|
run_linters=0
|
2018-06-28 12:53:49 +00:00
|
|
|
shift
|
|
|
|
;;
|
2017-05-12 19:38:52 +00:00
|
|
|
--vim-only)
|
2018-06-28 12:53:49 +00:00
|
|
|
run_neovim_02_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_neovim_04_tests=0
|
2018-07-01 11:06:36 +00:00
|
|
|
run_linters=0
|
2017-07-09 13:58:17 +00:00
|
|
|
shift
|
|
|
|
;;
|
2018-07-23 19:41:06 +00:00
|
|
|
--vim-80-only)
|
|
|
|
run_neovim_02_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_neovim_04_tests=0
|
|
|
|
run_vim_82_tests=0
|
2018-07-23 19:41:06 +00:00
|
|
|
run_linters=0
|
|
|
|
shift
|
|
|
|
;;
|
2021-01-27 19:52:24 +00:00
|
|
|
--vim-82-only)
|
2018-07-23 19:41:06 +00:00
|
|
|
run_neovim_02_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_neovim_04_tests=0
|
2018-07-23 19:41:06 +00:00
|
|
|
run_vim_80_tests=0
|
|
|
|
run_linters=0
|
|
|
|
shift
|
|
|
|
;;
|
2018-07-01 11:06:36 +00:00
|
|
|
--linters-only)
|
2018-07-23 19:41:06 +00:00
|
|
|
run_vim_80_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_vim_82_tests=0
|
2018-06-28 12:53:49 +00:00
|
|
|
run_neovim_02_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_neovim_04_tests=0
|
2017-08-10 09:45:12 +00:00
|
|
|
shift
|
|
|
|
;;
|
2020-08-16 20:19:07 +00:00
|
|
|
--fast)
|
|
|
|
run_vim_80_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_vim_82_tests=0
|
2020-08-16 20:19:07 +00:00
|
|
|
run_neovim_02_tests=0
|
2021-01-27 19:52:24 +00:00
|
|
|
run_neovim_04_tests=1
|
2020-08-16 20:19:07 +00:00
|
|
|
shift
|
|
|
|
;;
|
2018-07-01 18:56:17 +00:00
|
|
|
--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'
|
2021-01-27 19:52:24 +00:00
|
|
|
echo ' --build-image Run docker image build only.'
|
|
|
|
echo ' --neovim-only Run tests only for NeoVim'
|
2018-07-01 18:56:17 +00:00
|
|
|
echo ' --neovim-02-only Run tests only for NeoVim 0.2'
|
2021-01-27 19:52:24 +00:00
|
|
|
echo ' --neovim-04-only Run tests only for NeoVim 0.4'
|
|
|
|
echo ' --vim-only Run tests only for Vim'
|
2018-07-23 19:41:06 +00:00
|
|
|
echo ' --vim-80-only Run tests only for Vim 8.0'
|
2021-01-27 19:52:24 +00:00
|
|
|
echo ' --vim-82-only Run tests only for Vim 8.2'
|
2018-07-01 18:56:17 +00:00
|
|
|
echo ' --linters-only Run only Vint and custom checks'
|
2020-08-16 20:19:07 +00:00
|
|
|
echo ' --fast Run only the fastest Vim and custom checks'
|
2018-07-01 18:56:17 +00:00
|
|
|
echo ' --help Show this help text'
|
|
|
|
echo ' -- Stop parsing options after this'
|
|
|
|
exit 0
|
|
|
|
;;
|
2017-05-12 19:38:52 +00:00
|
|
|
--)
|
|
|
|
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="$*"
|
2018-06-28 13:00:12 +00:00
|
|
|
|
|
|
|
# Don't run other tools when targeting tests.
|
2018-07-01 11:06:36 +00:00
|
|
|
run_linters=0
|
2017-05-12 19:38:52 +00:00
|
|
|
fi
|
|
|
|
|
2017-08-22 20:08:32 +00:00
|
|
|
# Delete .swp files in the test directory, which cause Vim 8 to hang.
|
|
|
|
find test -name '*.swp' -delete
|
|
|
|
|
2021-01-27 19:52:24 +00:00
|
|
|
# Check if docker un image is available locally
|
|
|
|
has_image=$(docker images ls --filter reference="${image}:${image_tag}" --quiet | wc -l)
|
|
|
|
|
|
|
|
if [ "$has_image" -eq 0 ]
|
|
|
|
then
|
|
|
|
|
|
|
|
echo "Downloading run image ${image}:${image_tag}"
|
|
|
|
docker pull "${image}:${image_tag}" &> /dev/null
|
|
|
|
|
|
|
|
if [ $? -eq 1 ]
|
|
|
|
then
|
|
|
|
echo "Could not pull image ${image}:${image_tag}"
|
|
|
|
echo "Building run image ${image}:${image_tag}"
|
|
|
|
docker build --build-arg GIT_VERSION="$git_version" -t "${image}:${image_tag}" .
|
|
|
|
docker tag "${image}:${image_tag}" "${image}:latest"
|
|
|
|
|
|
|
|
if [[ -z "${DOCKER_HUB_USER:-}" || -z "${DOCKER_HUB_PASS:-}" ]]
|
|
|
|
then
|
|
|
|
echo "Docker Hub credentials not set, skip push"
|
|
|
|
else
|
|
|
|
echo "Push ${image}:${image_tag} to Docker Hub"
|
|
|
|
echo "$DOCKER_HUB_PASS" | docker login -u "$DOCKER_HUB_USER" --password-stdin
|
|
|
|
docker push "${image}:${image_tag}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Docker run image ${image}:${image_tag} ready"
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker tag "${image}:${image_tag}" "${image}:latest"
|
2017-05-12 19:38:52 +00:00
|
|
|
|
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=''
|
|
|
|
|
2019-05-12 14:42:09 +00:00
|
|
|
# Used for killing tests when you kill the script.
|
|
|
|
cancel_tests() {
|
|
|
|
set +e
|
|
|
|
|
|
|
|
if [ -n "$pid_list" ]; then
|
|
|
|
for pid in $pid_list; do
|
|
|
|
kill "$pid"
|
|
|
|
wait "$pid"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# shellcheck disable=SC2046
|
|
|
|
docker kill $(docker ps -a -q --filter ancestor="$image" --format='{{.ID}}') &> /dev/null
|
|
|
|
|
|
|
|
if [ -d "$output_dir" ]; then
|
|
|
|
rm -rf "$output_dir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cancel_tests INT TERM
|
|
|
|
|
2018-06-28 12:53:49 +00:00
|
|
|
for vim in $(docker run --rm "$DOCKER_RUN_IMAGE" ls /vim-build/bin | grep '^neovim\|^vim' ); do
|
2018-07-23 19:41:06 +00:00
|
|
|
if ( [[ $vim =~ ^vim-v8.0 ]] && ((run_vim_80_tests)) ) \
|
2021-01-27 19:52:24 +00:00
|
|
|
|| ( [[ $vim =~ ^vim-v8.2 ]] && ((run_vim_82_tests)) ) \
|
2018-06-28 12:53:49 +00:00
|
|
|
|| ( [[ $vim =~ ^neovim-v0.2 ]] && ((run_neovim_02_tests)) ) \
|
2021-01-27 19:52:24 +00:00
|
|
|
|| ( [[ $vim =~ ^neovim-v0.4 ]] && ((run_neovim_04_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 $!"
|
2017-12-01 17:50:19 +00:00
|
|
|
fi
|
|
|
|
done
|
2017-05-12 19:38:52 +00:00
|
|
|
|
2018-07-01 11:06:36 +00:00
|
|
|
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-05-12 19:38:52 +00:00
|
|
|
|
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 $!"
|
2017-05-12 19:38:52 +00:00
|
|
|
fi
|
|
|
|
|
2017-12-07 20:07:45 +00:00
|
|
|
echo
|
|
|
|
|
|
|
|
failed=0
|
|
|
|
index=0
|
|
|
|
|
|
|
|
for pid in $pid_list; do
|
2018-07-15 17:24:53 +00:00
|
|
|
this_failed=0
|
2017-12-07 20:07:45 +00:00
|
|
|
index=$((index+1))
|
|
|
|
|
|
|
|
if ! wait "$pid"; then
|
|
|
|
failed=1
|
2018-07-15 17:24:53 +00:00
|
|
|
this_failed=1
|
2017-12-07 20:07:45 +00:00
|
|
|
fi
|
|
|
|
|
2018-07-15 17:24:53 +00:00
|
|
|
# Hide output for things that passed if -q is set.
|
|
|
|
if [ "$quiet_flag" != '-q' ] || ((this_failed)); then
|
|
|
|
cat "$output_dir/$index"
|
|
|
|
fi
|
2017-12-07 20:07:45 +00:00
|
|
|
done
|
|
|
|
|
2018-06-28 12:53:49 +00:00
|
|
|
if ((failed)); then
|
|
|
|
echo 'Something went wrong!'
|
|
|
|
else
|
|
|
|
echo 'All tests passed!'
|
|
|
|
fi
|
|
|
|
|
2017-12-07 20:07:45 +00:00
|
|
|
exit $failed
|