#!/usr/bin/env bash
set -e
set -u
docker_flags=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$DOCKER_RUN_IMAGE")
red='\033[0;31m'
green='\033[0;32m'
nc='\033[0m'
verbose=0
quiet=0
exit_code=0
while [ $# -ne 0 ]; do
case $1 in
-v)
verbose=1
shift
;;
-q)
quiet=1
--)
break
-?*)
echo "Invalid argument: $1" 1>&2
exit 1
*)
esac
done
vim="$1"
tests="$2"
function filter-vader-output() {
# When verbose mode is off, suppress output until Vader starts.
local start_output="$verbose"
local filtered_data=''
while read -r; do
if ((!start_output)); then
if [[ "$REPLY" = *'Starting Vader:'* ]]; then
start_output=1
else
continue
fi
if ((quiet)); then
filtered_data="$REPLY"
elif [[ "$REPLY" = *'Success/Total'* ]]; then
success="$(echo -n "$REPLY" | grep -o '[0-9]\+/' | head -n1 | cut -d/ -f1)"
total="$(echo -n "$REPLY" | grep -o '/[0-9]\+' | head -n1 | cut -d/ -f2)"
if [ "$success" -lt "$total" ]; then
echo "$filtered_data"
echo "$REPLY"
filtered_data=''
filtered_data="$filtered_data"$'\n'"$REPLY"
}
function color-vader-output() {
if [[ "$REPLY" = *'[EXECUTE] (X)'* ]]; then
echo -en "$red"
elif [[ "$REPLY" = *'[EXECUTE]'* ]] || [[ "$REPLY" = *'[ GIVEN]'* ]]; then
echo -en "$nc"
if [[ "$REPLY" = *'Success/Total'* ]]; then
echo -en "$green"
echo
echo '========================================'
echo "Running tests for $vim"
set -o pipefail
docker run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${docker_flags[@]}" \
"/vim-build/bin/$vim" -u test/vimrc \
"+Vader! $tests" 2>&1 | filter-vader-output | color-vader-output || exit_code=$?
set +o pipefail
exit "$exit_code"