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-07-26 05:26:31 +02:00
|
|
|
# Say Hi
|
|
|
|
echo -en "Starting $(basename $0) for VimWiki\n"
|
2020-08-09 22:13:53 +02:00
|
|
|
start_time=`date +%s`
|
2020-07-26 05:26:31 +02:00
|
|
|
|
|
|
|
# For windows: Cmder bash is appending busybox to the path and
|
|
|
|
# and a smlll vim is included, so that override the windows path vim
|
|
|
|
if [[ -v OLD_PATH ]]; then
|
|
|
|
echo "Setting path from OLD_PATH : $OLD_PATH"
|
|
|
|
export PATH="$OLD_PATH"
|
|
|
|
fi
|
2020-05-31 00:06:42 +02:00
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
printHelp() {
|
2020-07-25 08:05:59 +02:00
|
|
|
cat << ' EOF' | sed -e 's/^ //'
|
|
|
|
Usage: bash run_tests.sh [OPTIONS]
|
|
|
|
|
|
|
|
Runs Vimwiki Vader tests or Vint in a Docker container
|
|
|
|
|
|
|
|
-h (Help) Print help message
|
|
|
|
|
|
|
|
-n (versioN) Specify vim/nvim version to run tests for.
|
2020-07-26 05:26:31 +02:00
|
|
|
Specify "local" to run on your current vim install
|
|
|
|
for example on Windows.
|
2020-07-25 08:05:59 +02:00
|
|
|
Multiple versions can be specified by quoting the value and
|
|
|
|
separating versions with a space. E.g. -n "vim1 vim2".
|
|
|
|
Default is all available versions.
|
|
|
|
|
2020-08-09 22:13:53 +02:00
|
|
|
-f (File) Space separated list of tests to run.
|
|
|
|
E.g. -o "list_* z_success"
|
2020-07-25 08:05:59 +02:00
|
|
|
|
|
|
|
-l (List) list available versions that can be used with the '-n' option
|
|
|
|
|
|
|
|
-t (Type) Select test type: 'vader', 'vint', or 'all'
|
|
|
|
|
|
|
|
-v (Verbose) Turn on verbose output.
|
|
|
|
|
2020-07-26 05:26:31 +02:00
|
|
|
E.g. On Linux
|
2020-08-09 22:13:53 +02:00
|
|
|
bash run_tests.sh -v -t vader -n "vim_7.4.1099 vim_8.1.0519" -f link_creation.vader issue_markdown.vader
|
2020-07-26 05:26:31 +02:00
|
|
|
E.g. On Windows
|
|
|
|
bash run_tests.sh -v -t vader -n local -f z_success.vader | cat
|
2020-07-25 08:05:59 +02:00
|
|
|
EOF
|
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
printVersions() {
|
2020-07-25 08:05:59 +02:00
|
|
|
# Print the names of all vim/nvim versions
|
2019-07-21 06:12:27 +02:00
|
|
|
getVers
|
2020-05-31 00:06:42 +02:00
|
|
|
exit 0
|
2019-07-21 06:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
runVader() {
|
2020-07-25 08:05:59 +02:00
|
|
|
# Run Vader tests
|
2020-07-26 05:26:31 +02:00
|
|
|
echo -e "\nStarting Vader tests."
|
|
|
|
local err=0
|
2019-07-21 06:12:27 +02:00
|
|
|
|
2020-07-25 08:05:59 +02:00
|
|
|
# Parse tests files to execute
|
|
|
|
if [[ -z $file_test ]]; then
|
2020-08-09 22:13:53 +02:00
|
|
|
ind="test/independent_runs/*.vader"
|
|
|
|
res="test/*"
|
2019-12-30 13:58:20 +01:00
|
|
|
else
|
2020-08-09 22:13:53 +02:00
|
|
|
read -ra TEST <<< "$file_test"
|
2019-12-30 13:58:20 +01:00
|
|
|
for i in "${TEST[@]}"; do
|
2020-08-09 22:13:53 +02:00
|
|
|
if [[ "$i" == "independent_runs/"*"*"* ]]; then
|
|
|
|
ind="$ind test/${i}"
|
|
|
|
elif [[ "$i" == *"*"* ]]; then
|
|
|
|
res="$res test/${i}"
|
|
|
|
elif [[ -f "$i" ]]; then
|
2019-12-30 13:58:20 +01:00
|
|
|
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
|
|
|
|
|
2020-07-25 08:05:59 +02:00
|
|
|
# Run tests for each specified version
|
2019-07-21 06:12:27 +02:00
|
|
|
for v in $vers; do
|
2020-08-09 22:13:53 +02:00
|
|
|
echo -e "\n\nRunning version: $v"
|
|
|
|
echo -e "============================="
|
2020-07-26 05:26:31 +02:00
|
|
|
|
|
|
|
# Set local environment variables
|
|
|
|
if [[ "$v" == "local" ]]; then
|
|
|
|
# Save HOME var
|
|
|
|
home_save="$HOME"
|
|
|
|
|
|
|
|
# Create temporary root
|
|
|
|
mkdir -p $tmp_dir/vader_wiki
|
|
|
|
mkdir -p $tmp_dir/vader_wiki/home
|
|
|
|
mkdir -p $tmp_dir/vader_wiki/home/test
|
|
|
|
mkdir -p $tmp_dir/vader_wiki/testplugin
|
|
|
|
|
|
|
|
# Set vars
|
|
|
|
export ROOT="$tmp_dir/vader_wiki/"
|
|
|
|
export HOME="$tmp_dir/vader_wiki/home"
|
|
|
|
vim="vim"
|
2020-08-09 22:13:53 +02:00
|
|
|
vim_opt="-u ~/test/vimrc"
|
2020-07-26 05:26:31 +02:00
|
|
|
else
|
|
|
|
# Only set dockerized vars
|
|
|
|
export ROOT="/" # So no if in vimrc
|
|
|
|
vim="/vim-build/bin/$v"
|
2020-08-09 22:13:53 +02:00
|
|
|
vim_opt="-u test/vimrc"
|
2020-07-26 05:26:31 +02:00
|
|
|
fi
|
2019-12-14 03:58:08 +01:00
|
|
|
|
2020-08-09 22:13:53 +02:00
|
|
|
# Too talkative TODO make a verbose level 1..10 an 1 is not taking vim
|
|
|
|
#if [[ "$verbose" != 0 ]]; then
|
|
|
|
# vim_opt+=' -V1'
|
|
|
|
#fi
|
|
|
|
# IDK why vim with -Es is returning ! and make fail:
|
|
|
|
# -- tabnext profiling
|
|
|
|
# -- map.vim
|
|
|
|
vim_opt+=' -i NONE -Es '
|
|
|
|
|
|
|
|
# set -o pipefail
|
2019-12-14 03:58:08 +01:00
|
|
|
|
2020-07-26 05:26:31 +02:00
|
|
|
# Copy the resources to temporary directory
|
|
|
|
if [[ "$v" == "local" ]]; then
|
|
|
|
# flags=(--rm -v "$PWD/../:/testplugin" -v "$PWD/../test:/home" -w /testplugin vimwiki)
|
|
|
|
echo -e "\nCopying resources to $ROOT"
|
|
|
|
# Copy testplugin
|
|
|
|
cp -rf $wiki_path/* $ROOT/testplugin/
|
|
|
|
# Copy home
|
|
|
|
cp -rf $script_path/* $HOME/test/
|
|
|
|
# Copy rtp.vim
|
|
|
|
cp -rf $script_path/resources/rtp_local.vim $ROOT/rtp.vim
|
|
|
|
# Copy vader <- internet
|
|
|
|
echo 'Cloning Vader (git, do not care the fatal)'
|
|
|
|
git clone --depth 10 https://github.com/junegunn/vader.vim /tmp/vader_wiki/vader 2>&1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Run batch of tests
|
2020-08-09 22:13:53 +02:00
|
|
|
if [[ "$res" != "" ]]; then
|
|
|
|
if [[ "$v" == "local" ]]; then
|
|
|
|
pushd $tmp_dir/vader_wiki/testplugin
|
|
|
|
|
|
|
|
# Run the tests
|
|
|
|
echo -e "\nStarting Batch Vim/Vader <- $res"
|
|
|
|
"$vim" $vim_opt "+Vader! ${res}" 2>&1
|
|
|
|
ret=${PIPESTATUS[1]}; err=$(( $err + $ret ))
|
|
|
|
echo -e "\nReturned Batch Vim/Vader -> $ret"
|
|
|
|
|
|
|
|
popd
|
|
|
|
else
|
|
|
|
# In docker
|
|
|
|
echo -e "\nStarting Independant Vim/Vader <- $res"
|
|
|
|
docker run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${flags[@]}" \
|
|
|
|
"$v" $vim_opt "+Vader! ${res}" 2>&1 | vader_filter | vader_color
|
|
|
|
ret=${PIPESTATUS[1]}; err=$(( $err + $ret ))
|
|
|
|
echo -e "\nReturned Independant Docker/Vim/Vader -> $ret"
|
|
|
|
fi
|
2020-07-26 05:26:31 +02:00
|
|
|
fi
|
2019-12-14 03:58:08 +01:00
|
|
|
|
2020-07-25 08:05:59 +02:00
|
|
|
# Run Tests that must be run in individual vim instances
|
|
|
|
# see README.md for more information
|
2020-08-09 22:13:53 +02:00
|
|
|
if [[ "$ind" != "" ]]; then
|
|
|
|
test_cmd="for VF in ${ind}; do $vim $vim_opt \"+Vader! \$VF\"; done"
|
|
|
|
if [[ "$v" == "local" ]]; then
|
|
|
|
pushd $tmp_dir/vader_wiki/testplugin
|
|
|
|
|
|
|
|
echo -e "\nStarting Vim/Vader <- $test_cmd"
|
|
|
|
bash -c "$test_cmd" 2>&1
|
|
|
|
ret=${PIPESTATUS[1]}; err=$(( $err + $ret ))
|
|
|
|
echo -e "\nReturned Vim/Vader -> $ret"
|
|
|
|
|
|
|
|
popd
|
|
|
|
else # In docker
|
|
|
|
echo -e "\nStarting Docker/Vim/Vader <- $test_cmd"
|
|
|
|
docker run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${flags[@]}" \
|
|
|
|
/bin/bash -c "$test_cmd" 2>&1 | vader_filter | vader_color
|
|
|
|
ret=${PIPESTATUS[1]}; err=$(( $err + $ret ))
|
|
|
|
echo -e "\nReturned Docker/Vim/Vader -> $ret"
|
|
|
|
fi
|
2020-07-26 05:26:31 +02:00
|
|
|
fi
|
2020-07-25 08:05:59 +02:00
|
|
|
|
2020-08-09 22:13:53 +02:00
|
|
|
#set +o pipefail
|
2020-07-26 05:26:31 +02:00
|
|
|
|
|
|
|
# Restore what must (I know it should be refactored in a while)
|
|
|
|
if [[ "$v" == "local" ]]; then
|
|
|
|
export HOME=$home_save
|
|
|
|
fi
|
2019-07-21 06:12:27 +02:00
|
|
|
done
|
2020-07-26 05:26:31 +02:00
|
|
|
return $err
|
2019-07-21 06:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
runVint() {
|
2020-07-26 05:26:31 +02:00
|
|
|
local err=0
|
|
|
|
cmd="vint -s . && vint -s test/vimrc"
|
|
|
|
if echo "$vers" | grep "local" > /dev/null; then
|
2020-07-26 23:55:47 +02:00
|
|
|
echo -e "\nRunning Vint: $cmd : in $wiki_path"
|
2020-07-26 05:26:31 +02:00
|
|
|
pushd $wiki_path > /dev/null
|
|
|
|
$cmd
|
|
|
|
err=$(( $err | $? ))
|
|
|
|
popd > /dev/null
|
|
|
|
else
|
2020-07-26 23:55:47 +02:00
|
|
|
echo -e "\nStarting Docker container and running Vint: $cmd"
|
2020-07-26 05:26:31 +02:00
|
|
|
docker run -a stdout "${flags[@]}" bash -c "$cmd"
|
|
|
|
err=$(( $err | $? ))
|
|
|
|
fi
|
|
|
|
return $err
|
2019-07-21 06:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getVers() {
|
2020-08-09 22:13:53 +02:00
|
|
|
# Get all possible version <- Dockerfile
|
2019-07-21 06:12:27 +02:00
|
|
|
sed -n 's/.* -name \([^ ]*\) .*/\1/p' ../Dockerfile
|
|
|
|
}
|
|
|
|
|
|
|
|
vader_filter() {
|
2020-07-25 08:05:59 +02:00
|
|
|
# Filter Vader Stdout
|
2019-07-21 06:12:27 +02:00
|
|
|
local err=0
|
2020-08-09 22:13:53 +02:00
|
|
|
# Keep indentation
|
|
|
|
local IFS=''
|
|
|
|
while read -r REPLY; do
|
2020-07-25 08:05:59 +02:00
|
|
|
# Print only possible error cases
|
2020-08-09 22:13:53 +02:00
|
|
|
if [[ "$REPLY" = *'docker:'* ]] || \
|
|
|
|
[[ "$REPLY" = *'Starting Vader:'* ]] || \
|
|
|
|
[[ "$REPLY" = *'Vader error:'* ]] || \
|
|
|
|
[[ "$REPLY" = *'Vim: Error '* ]]; then
|
|
|
|
echo "$REPLY"
|
|
|
|
elif [[ "$REPLY" = *'[EXECUTE] (X)'* ]] || \
|
|
|
|
[[ "$REPLY" = *'[ EXPECT] (X)'* ]]; then
|
|
|
|
echo "$REPLY"
|
|
|
|
err=1
|
|
|
|
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
|
2019-07-25 05:57:01 +02:00
|
|
|
err=1
|
2019-07-21 06:12:27 +02:00
|
|
|
fi
|
2020-08-09 22:13:53 +02:00
|
|
|
echo "$REPLY"
|
|
|
|
elif [[ "$verbose" != 0 ]]; then
|
2019-07-21 06:12:27 +02:00
|
|
|
# just print everything
|
|
|
|
echo "$REPLY"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "$err" == 1 ]]; then
|
2020-08-09 22:13:53 +02:00
|
|
|
echo -e "\033[0;31m"
|
|
|
|
echo -e "!---------Failed tests detected---------!"
|
|
|
|
echo -e "Run with the '-v' flag for verbose output"
|
|
|
|
echo -e "\033[0m"
|
2019-07-21 06:12:27 +02:00
|
|
|
fi
|
2020-07-26 05:26:31 +02:00
|
|
|
return $err
|
2019-07-21 06:12:27 +02:00
|
|
|
}
|
|
|
|
|
2020-05-13 17:33:37 +02:00
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2020-07-26 05:26:31 +02:00
|
|
|
# path of the script, supposing no spaces
|
|
|
|
script_file="$(dirname $0)"
|
|
|
|
script_path="$( realpath $script_file )"
|
|
|
|
wiki_path="$( realpath $script_path/.. )"
|
|
|
|
tmp_dir=$(dirname $(mktemp -u))
|
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
# 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
|
2020-07-25 08:05:59 +02:00
|
|
|
file_test=""
|
2019-12-30 13:58:20 +01:00
|
|
|
|
2019-07-21 06:12:27 +02:00
|
|
|
# docker flags
|
|
|
|
flags=(--rm -v "$PWD/../:/testplugin" -v "$PWD/../test:/home" -w /testplugin vimwiki)
|
|
|
|
|
2020-07-25 08:05:59 +02:00
|
|
|
while getopts ":hvn:lt:f:" 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"
|
|
|
|
;;
|
2020-07-25 08:05:59 +02:00
|
|
|
f )
|
|
|
|
file_test="$OPTARG"
|
2019-12-30 13:58:20 +01:00
|
|
|
;;
|
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
|
|
|
|
|
2020-07-26 05:26:31 +02:00
|
|
|
# Global error return of the script
|
|
|
|
o_error=0
|
|
|
|
|
2020-08-09 22:13:53 +02:00
|
|
|
# Select which tests should run
|
2019-07-21 06:12:27 +02:00
|
|
|
case $type in
|
|
|
|
"vader" )
|
2020-06-16 20:48:15 +02:00
|
|
|
runVader ; err=$?
|
2020-08-09 22:13:53 +02:00
|
|
|
echo "Main Vader: returned $err"
|
2020-06-16 20:48:15 +02:00
|
|
|
o_error=$(( $err | $o_error ))
|
2019-07-21 06:12:27 +02:00
|
|
|
;;
|
|
|
|
"vint" )
|
2020-06-16 20:48:15 +02:00
|
|
|
runVint ; err=$?
|
2020-08-09 22:13:53 +02:00
|
|
|
echo "Main Vint: returned $err"
|
2020-06-16 20:48:15 +02:00
|
|
|
o_error=$(( $err | $o_error ))
|
2019-07-21 06:12:27 +02:00
|
|
|
;;
|
|
|
|
"all" )
|
2020-06-16 20:48:15 +02:00
|
|
|
runVint ; err=$?
|
2020-08-09 22:13:53 +02:00
|
|
|
echo "Main Vint: returned $err"
|
2020-06-16 20:48:15 +02:00
|
|
|
o_error=$(( $err | $o_error ))
|
|
|
|
runVader ; err=$?
|
2020-08-09 22:13:53 +02:00
|
|
|
echo "Main Vader: returned $err"
|
2020-06-16 20:48:15 +02:00
|
|
|
o_error=$(( $err | $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-08-09 22:13:53 +02:00
|
|
|
# Calcultate time
|
|
|
|
end_time=`date +%s`
|
|
|
|
sec_time=$((end_time - start_time))
|
|
|
|
printf -v script_time '%dh:%dm:%ds' $(($sec_time/3600)) $(($sec_time%3600/60)) $(($sec_time%60))
|
|
|
|
|
2020-05-31 00:06:42 +02:00
|
|
|
# Exit
|
2020-08-09 22:13:53 +02:00
|
|
|
echo -ne "Script $(basename $0), in $script_time, Returned -> $o_error\n\n"
|
2020-05-13 17:33:37 +02:00
|
|
|
exit $o_error
|