2019-07-21 06:12:27 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# credit to https://github.com/w0rp/ale for script ideas and the color vader
|
|
|
|
# output function.
|
|
|
|
|
2020-05-31 00:06:42 +02:00
|
|
|
# Global error return of the script
|
|
|
|
o_error=0
|
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
printHelp() {
|
|
|
|
echo "Usage: $0 [OPTIONS]"
|
|
|
|
echo ""
|
|
|
|
echo "Runs Vimwiki Vader tests or Vint in a Docker container"
|
|
|
|
echo ""
|
|
|
|
echo "-h Print help message"
|
|
|
|
echo ""
|
|
|
|
echo "-n Specify vim/nvim version to run tests for."
|
|
|
|
echo " Multiple versions can be specified by quoting the value and"
|
2020-05-31 00:06:42 +02:00
|
|
|
echo " separating versions with a space. E.g. -n \"vim1 vim2\"."
|
2019-07-21 06:12:27 +02:00
|
|
|
echo " Default is all available versions."
|
|
|
|
echo ""
|
2020-05-31 00:06:42 +02:00
|
|
|
echo "-l List available versions that can be used with the '-n' option"
|
2019-07-21 06:12:27 +02:00
|
|
|
echo ""
|
|
|
|
echo "-t Select test type: 'vader', 'vint', or 'all'"
|
|
|
|
echo ""
|
2019-12-30 13:58:20 +01:00
|
|
|
echo "-o Comma seperated list of tests to run."
|
|
|
|
echo " E.g. -o \"list_margin,command_toc\""
|
|
|
|
echo ""
|
2019-07-21 06:12:27 +02:00
|
|
|
echo "-v Turn on verbose output."
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
printVersions() {
|
|
|
|
# print the names of all vim/nvim versions
|
|
|
|
getVers
|
2020-05-31 00:06:42 +02:00
|
|
|
exit 0
|
2019-07-21 06:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
runVader() {
|
|
|
|
echo "Starting Docker container and Vader tests."
|
|
|
|
|
2019-12-30 13:58:20 +01:00
|
|
|
if [[ -z $only ]]; then
|
|
|
|
ind="test/independent_runs/*.vader"
|
|
|
|
res="test/*"
|
|
|
|
else
|
|
|
|
IFS=',' read -ra TEST <<< "$only"
|
|
|
|
for i in "${TEST[@]}"; do
|
|
|
|
if [[ -f "$i" ]]; then
|
|
|
|
res="$res test/${i}"
|
|
|
|
elif [[ -f "${i}.vader" ]]; then
|
|
|
|
res="$res test/${i}.vader"
|
|
|
|
elif [[ -f "independent_runs/${i}" ]]; then
|
|
|
|
ind="$ind test/independent_runs/${i}"
|
|
|
|
elif [[ -f "independent_runs/${i}.vader" ]]; then
|
|
|
|
ind="$ind test/independent_runs/${i}.vader"
|
|
|
|
else
|
|
|
|
printf "WARNING: Test \"%s\" not found.\n", "$i"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
# run tests for each specified version
|
|
|
|
for v in $vers; do
|
|
|
|
echo ""
|
|
|
|
echo "Running version: $v"
|
2019-10-13 00:31:43 +02:00
|
|
|
vim="/vim-build/bin/$v -u test/vimrc -i NONE"
|
2019-12-30 13:58:20 +01:00
|
|
|
test_cmd="for VF in ${ind}; do $vim \"+Vader! \$VF\"; done"
|
2019-12-14 03:58:08 +01:00
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
set -o pipefail
|
2019-12-14 03:58:08 +01:00
|
|
|
|
|
|
|
# tests that must be run in individual vim instances
|
|
|
|
# see README.md for more information
|
2019-07-21 06:12:27 +02:00
|
|
|
docker run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${flags[@]}" \
|
2019-10-13 00:31:43 +02:00
|
|
|
/bin/bash -c "$test_cmd" 2>&1 | vader_filter | vader_color
|
2020-05-31 00:06:42 +02:00
|
|
|
o_error=$(( $o_error | $? ))
|
2019-12-14 03:58:08 +01:00
|
|
|
|
|
|
|
# remaining tests
|
|
|
|
docker run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${flags[@]}" \
|
2019-12-30 13:58:20 +01:00
|
|
|
"$v" -u test/vimrc -i NONE "+Vader! ${res}" 2>&1 | vader_filter | vader_color
|
2020-05-31 00:06:42 +02:00
|
|
|
o_error=$(( $o_error | $? ))
|
2019-07-21 06:12:27 +02:00
|
|
|
set +o pipefail
|
|
|
|
done
|
2020-05-31 00:06:42 +02:00
|
|
|
return $o_error
|
2019-07-21 06:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
runVint() {
|
|
|
|
echo "Starting Docker container and running Vint."
|
|
|
|
|
|
|
|
docker run -a stdout "${flags[@]}" vint -s .
|
|
|
|
}
|
|
|
|
|
|
|
|
getVers() {
|
|
|
|
sed -n 's/.* -name \([^ ]*\) .*/\1/p' ../Dockerfile
|
|
|
|
}
|
|
|
|
|
|
|
|
vader_filter() {
|
|
|
|
local err=0
|
|
|
|
while read -r; do
|
|
|
|
if [[ "$verbose" == 0 ]]; then
|
2019-07-25 05:57:01 +02:00
|
|
|
# only print possible error cases
|
|
|
|
if [[ "$REPLY" = *'docker:'* ]] || \
|
|
|
|
[[ "$REPLY" = *'Starting Vader:'* ]] || \
|
|
|
|
[[ "$REPLY" = *'Vader error:'* ]] || \
|
|
|
|
[[ "$REPLY" = *'Vim: Error '* ]]; then
|
2019-07-21 06:12:27 +02:00
|
|
|
echo "$REPLY"
|
2019-07-25 05:57:01 +02:00
|
|
|
elif [[ "$REPLY" = *'[EXECUTE] (X)'* ]] || \
|
|
|
|
[[ "$REPLY" = *'[ EXPECT] (X)'* ]]; then
|
2019-07-21 06:12:27 +02:00
|
|
|
echo "$REPLY"
|
2019-07-25 05:57:01 +02:00
|
|
|
err=1
|
2019-07-21 06:12:27 +02:00
|
|
|
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
|
|
|
|
err=1
|
|
|
|
fi
|
|
|
|
echo "$REPLY"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# just print everything
|
|
|
|
echo "$REPLY"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "$err" == 1 ]]; then
|
2020-05-31 00:06:42 +02:00
|
|
|
o_error=1
|
2019-07-21 06:12:27 +02:00
|
|
|
echo ""
|
|
|
|
echo "!---------Failed tests detected---------!"
|
|
|
|
echo "Run with the '-v' flag for verbose output"
|
|
|
|
echo ""
|
|
|
|
fi
|
2020-05-31 00:06:42 +02:00
|
|
|
return $o_error
|
2019-07-21 06:12:27 +02:00
|
|
|
}
|
|
|
|
|
2020-05-13 17:33:37 +02:00
|
|
|
# Say Hi
|
|
|
|
echo -en "Starting $(basename $0) for VimWiki\n"
|
|
|
|
|
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
red='\033[0;31m'
|
|
|
|
green='\033[0;32m'
|
|
|
|
nc='\033[0m'
|
|
|
|
vader_color() {
|
|
|
|
while read -r; do
|
|
|
|
if [[ "$REPLY" = *'[EXECUTE] (X)'* ]] || \
|
|
|
|
[[ "$REPLY" = *'[ EXPECT] (X)'* ]] || \
|
|
|
|
[[ "$REPLY" = *'Vim: Error '* ]] || \
|
|
|
|
[[ "$REPLY" = *'Vader error:'* ]]; then
|
|
|
|
echo -en "$red"
|
|
|
|
elif [[ "$REPLY" = *'[EXECUTE]'* ]] || [[ "$REPLY" = *'[ GIVEN]'* ]]; then
|
|
|
|
echo -en "$nc"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$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 -en "$red"
|
|
|
|
else
|
|
|
|
echo -en "$green"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$REPLY"
|
|
|
|
echo -en "$nc"
|
|
|
|
else
|
|
|
|
echo "$REPLY"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo -en "$nc"
|
|
|
|
}
|
|
|
|
|
|
|
|
# list of vim/nvim versions
|
|
|
|
vers="$(getVers)"
|
|
|
|
|
|
|
|
# type of tests to run - vader/vint/all
|
|
|
|
type="all"
|
|
|
|
|
|
|
|
# verbose output flag
|
|
|
|
verbose=0
|
|
|
|
|
2019-12-30 13:58:20 +01:00
|
|
|
# only run these tests
|
|
|
|
only=""
|
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
# docker flags
|
|
|
|
flags=(--rm -v "$PWD/../:/testplugin" -v "$PWD/../test:/home" -w /testplugin vimwiki)
|
|
|
|
|
2019-12-30 13:58:20 +01:00
|
|
|
while getopts ":hvn:lt:o:" opt; do
|
2019-07-21 06:12:27 +02:00
|
|
|
case ${opt} in
|
|
|
|
h )
|
|
|
|
printHelp
|
|
|
|
;;
|
|
|
|
n )
|
|
|
|
vers="$OPTARG"
|
|
|
|
;;
|
|
|
|
v )
|
|
|
|
verbose=1
|
|
|
|
;;
|
|
|
|
l )
|
|
|
|
printVersions
|
|
|
|
;;
|
|
|
|
t )
|
|
|
|
type="$OPTARG"
|
|
|
|
;;
|
2019-12-30 13:58:20 +01:00
|
|
|
o )
|
|
|
|
only="$OPTARG"
|
|
|
|
;;
|
2019-07-21 06:12:27 +02:00
|
|
|
\? )
|
|
|
|
echo "Invalid option: $OPTARG" 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
: )
|
|
|
|
echo "Invalid option: $OPTARG requires an argument" 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# shift out processed parameters
|
|
|
|
shift $((OPTIND -1))
|
|
|
|
|
|
|
|
# error handling for non-option arguments
|
|
|
|
if [[ $# -ne 0 ]]; then
|
|
|
|
echo "Error: Got $# non-option arguments." 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-07-25 05:57:01 +02:00
|
|
|
# stop tests on ctrl-c or ctrl-z
|
|
|
|
trap exit 1 SIGINT SIGTERM
|
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
# select which tests should run
|
|
|
|
case $type in
|
|
|
|
"vader" )
|
|
|
|
runVader
|
2020-05-20 20:41:07 +02:00
|
|
|
echo "Vader: returned $?"
|
2020-05-13 17:33:37 +02:00
|
|
|
o_error=$(( $? | $o_error ))
|
2019-07-21 06:12:27 +02:00
|
|
|
;;
|
|
|
|
"vint" )
|
|
|
|
runVint
|
2020-05-20 20:41:07 +02:00
|
|
|
echo "Vint: returned $?"
|
2020-05-13 17:33:37 +02:00
|
|
|
o_error=$(( $? | $o_error ))
|
2019-07-21 06:12:27 +02:00
|
|
|
;;
|
|
|
|
"all" )
|
|
|
|
runVint
|
2020-05-20 20:41:07 +02:00
|
|
|
echo "Vint: returned $?"
|
2020-05-13 17:33:37 +02:00
|
|
|
o_error=$(( $? | $o_error ))
|
2019-07-21 06:12:27 +02:00
|
|
|
runVader
|
2020-05-20 20:41:07 +02:00
|
|
|
echo "Vader: returned $?"
|
2020-05-13 17:33:37 +02:00
|
|
|
o_error=$(( $? | $o_error ))
|
2019-07-21 06:12:27 +02:00
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "Error: invalid type - '$type'" 1>&2
|
|
|
|
exit 1
|
|
|
|
esac
|
2020-05-13 17:33:37 +02:00
|
|
|
|
2020-05-31 00:06:42 +02:00
|
|
|
# Exit
|
2020-05-13 17:33:37 +02:00
|
|
|
echo "Script $(basename $0) exiting: $o_error"
|
|
|
|
exit $o_error
|