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