commit dec6a9ecab3e5ec9ceff28b84cabb5c62d05ee9f
parent 57107c7c560580a4f6a28f65ac85ea9ee70fd3e8
Author: Tinmarino <tinmarino@gmail.com>
Date: Wed, 22 Mar 2023 01:22:25 -0300
CI: Lint run_test: reorder function in top>down
Diffstat:
M | test/run_tests.sh | | | 351 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
1 file changed, 177 insertions(+), 174 deletions(-)
diff --git a/test/run_tests.sh b/test/run_tests.sh
@@ -10,13 +10,9 @@ Credit: https://github.com/w0rp/ale for script ideas and the color vader output
# Capture start time now
declare -g start_time=$(date +%s)
-# Declare color helper
-declare -g red='\033[0;31m'
-declare -g green='\033[0;32m'
-declare -g nc='\033[0m'
-
printHelp() {
+ : 'Print usage to stdout'
cat << ' EOF' | sed -e 's/^ //'
Usage: bash run_tests.sh [OPTIONS]
@@ -54,8 +50,144 @@ printHelp() {
}
+run_test(){
+ : 'Main function'
+ local -i res=0
+
+ # Hi
+ echo -en "Starting $(basename "$0") for VimWiki\n"
+
+ # Hook ctrl-c or ctrl-z to stop tests
+ trap exit 1 SIGINT SIGTERM
+
+ # 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
+
+ # WORK
+ parse_argument "$@"; ((res |= $?))
+ execute_test_argument; ((res |= $?))
+
+ # Print ellapsed time (after calculate it)
+ 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))
+ echo -ne "Script $(basename "$0"), in $script_time, Returned -> $res\n\n"
+
+ return "$res"
+}
+
+
+parse_argument(){
+ : 'Parse user argument'
+ # Declare color helper
+ declare -g red='\033[0;31m'
+ declare -g green='\033[0;32m'
+ declare -g nc='\033[0m'
+
+ # Declare: Path of the script, supposing no spaces
+ declare -g g_script_file=$(dirname "$0")
+ declare -g g_script_path=$(realpath "$g_script_file")
+ declare -g g_wiki_path=$(realpath "$g_script_path/..")
+ declare -g g_tmp_dir=$(dirname "$(mktemp -u)")
+
+ # Declare: list of vim/nvim versions
+ declare -g g_vers="$(print_versions)"
+
+ # Declare: type of tests to run - vader/vint/all
+ declare -g g_type="all"
+
+ # Declare: verbose output flag
+ declare -g g_verbose=0
+
+ # Declare: only run these tests
+ declare -g g_file_test=""
+
+ # Declare: docker flags
+ declare -g flags=(--rm -v "$PWD/../:/testplugin" -v "$PWD/../test:/home" -w /testplugin vimwiki)
+
+ # Parse all argument options
+ while getopts ":hvn:lt:f:" opt; do
+ case ${opt} in
+ h)
+ printHelp
+ ;;
+ n)
+ g_vers="$OPTARG"
+ ;;
+ v)
+ g_verbose=1
+ ;;
+ l)
+ print_versions
+ ;;
+ t)
+ g_type="$OPTARG"
+ ;;
+ f)
+ g_file_test="$OPTARG"
+ ;;
+ \?)
+ echo "Invalid option: $OPTARG" 1>&2
+ exit 1
+ ;;
+ :)
+ echo "Invalid option: $OPTARG requires an argument" 1>&2
+ exit 1
+ ;;
+ esac
+ done
+
+ # Shift out parameters already processed
+ shift $((OPTIND -1))
+
+ # Handle error for non-option arguments
+ if [[ $# -ne 0 ]]; then
+ echo "Error: Got $# non-option arguments." 1>&2
+ exit 1
+ fi
+}
+
+
+execute_test_argument(){
+ : 'Execute test according to global variable'
+ # Global error return of the script
+ local -i res=0 ret=0
+
+ # Select and run tests
+ case $g_type in
+ vader)
+ run_vader; ret=$?
+ echo "Main Vader: returned $ret"
+ ((res |= ret))
+ ;;
+ vint)
+ run_vint; ret=$?
+ echo "Main Vint: returned $ret"
+ ((res |= ret))
+ ;;
+ all)
+ run_vint; ret=$?
+ echo "Main Vint: returned $ret"
+ ((res |= ret))
+ run_vader; ret=$?
+ echo "Main Vader: returned $ret"
+ ((res |= ret))
+ ;;
+ *)
+ echo "Error: invalid type - '$g_type'" 1>&2
+ exit 1
+ esac
+
+ return "$res"
+}
+
+
print_versions() {
- # Print the names of all vim/nvim versions
+ : 'Print the names of all vim/nvim versions'
# Get all possible version <- Dockerfile
sed -n 's/.* -name \([^ ]*\) .*/\1/p' ../Dockerfile
exit 0
@@ -63,7 +195,7 @@ print_versions() {
run_vader() {
- # Run Vader tests
+ : 'Run Vader tests'
echo -e "\nStarting Vader tests."
local -i res=0
local opt='' current_test=''
@@ -193,6 +325,7 @@ run_vader() {
run_vint() {
+ : 'Run Vint test'
local -i res=0
local cmd="vint -s . && vint -s test/vimrc"
@@ -216,48 +349,49 @@ run_vint() {
vader_filter() {
- # Filter Vader Stdout
- local -i res=0
- # Keep indentation
- local IFS=''
-
- while read -r REPLY; do
- # Print only possible error cases
- if [[ "$REPLY" = *'docker:'* ]] || \
- [[ "$REPLY" = *'Starting Vader:'* ]] || \
- [[ "$REPLY" = *'Vader error:'* ]] || \
- [[ "$REPLY" = *'Vim: Error '* ]]; then
- echo "$REPLY"
- elif [[ "$REPLY" = *'[EXECUTE] (X)'* ]] || \
- [[ "$REPLY" = *'[ DO] (X)'* ]] || \
- [[ "$REPLY" = *'[ EXPECT] (X)'* ]]; then
- echo -e "$red$REPLY$nc"
- res=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
- res=1
- fi
- echo "$REPLY"
- elif [[ "$g_verbose" != 0 ]]; then
- # just print everything
- echo "$REPLY"
- fi
- done
-
- if (( res == 1 )); then
- echo -e "\033[0;31m"
- echo -e "!---------Failed tests detected---------!"
- echo -e "Run with the '-v' flag for verbose output"
- echo -e "\033[0m"
+ : 'Pipe Helper: Filter Vader Stdout'
+ local -i res=0
+ # Keep indentation
+ local IFS=''
+
+ while read -r REPLY; do
+ # Print only possible error cases
+ if [[ "$REPLY" = *'docker:'* ]] || \
+ [[ "$REPLY" = *'Starting Vader:'* ]] || \
+ [[ "$REPLY" = *'Vader error:'* ]] || \
+ [[ "$REPLY" = *'Vim: Error '* ]]; then
+ echo "$REPLY"
+ elif [[ "$REPLY" = *'[EXECUTE] (X)'* ]] || \
+ [[ "$REPLY" = *'[ DO] (X)'* ]] || \
+ [[ "$REPLY" = *'[ EXPECT] (X)'* ]]; then
+ echo -e "$red$REPLY$nc"
+ res=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
+ res=1
+ fi
+ echo "$REPLY"
+ elif [[ "$g_verbose" != 0 ]]; then
+ # just print everything
+ echo "$REPLY"
fi
+ done
- return "$res"
+ if (( res == 1 )); then
+ echo -e "\033[0;31m"
+ echo -e "!---------Failed tests detected---------!"
+ echo -e "Run with the '-v' flag for verbose output"
+ echo -e "\033[0m"
+ fi
+
+ return "$res"
}
vader_color() {
+ : 'Pipe Helper: Filter to add color to Vader'
while read -r; do
if [[ "$REPLY" = *'[EXECUTE] (X)'* ]] || \
[[ "$REPLY" = *'[ EXPECT] (X)'* ]] || \
@@ -289,137 +423,6 @@ vader_color() {
}
-parse_argument(){
- : 'Parse user argument'
-
- # Declare: Path of the script, supposing no spaces
- declare -g g_script_file=$(dirname "$0")
- declare -g g_script_path=$(realpath "$g_script_file")
- declare -g g_wiki_path=$(realpath "$g_script_path/..")
- declare -g g_tmp_dir=$(dirname "$(mktemp -u)")
-
- # Declare: list of vim/nvim versions
- declare -g g_vers="$(print_versions)"
-
- # Declare: type of tests to run - vader/vint/all
- declare -g g_type="all"
-
- # Declare: verbose output flag
- declare -g g_verbose=0
-
- # Declare: only run these tests
- declare -g g_file_test=""
-
- # Declare: docker flags
- declare -g flags=(--rm -v "$PWD/../:/testplugin" -v "$PWD/../test:/home" -w /testplugin vimwiki)
-
- # Parse all argument options
- while getopts ":hvn:lt:f:" opt; do
- case ${opt} in
- h)
- printHelp
- ;;
- n)
- g_vers="$OPTARG"
- ;;
- v)
- g_verbose=1
- ;;
- l)
- print_versions
- ;;
- t)
- g_type="$OPTARG"
- ;;
- f)
- g_file_test="$OPTARG"
- ;;
- \?)
- echo "Invalid option: $OPTARG" 1>&2
- exit 1
- ;;
- :)
- echo "Invalid option: $OPTARG requires an argument" 1>&2
- exit 1
- ;;
- esac
- done
-
- # Shift out parameters already processed
- shift $((OPTIND -1))
-
- # Handle error for non-option arguments
- if [[ $# -ne 0 ]]; then
- echo "Error: Got $# non-option arguments." 1>&2
- exit 1
- fi
-}
-
-
-execute_test_argument(){
- : 'Execute test according to global variable'
- # Global error return of the script
- local -i res=0 ret=0
-
- # Select and run tests
- case $g_type in
- vader)
- run_vader; ret=$?
- echo "Main Vader: returned $ret"
- ((res |= ret))
- ;;
- vint)
- run_vint; ret=$?
- echo "Main Vint: returned $ret"
- ((res |= ret))
- ;;
- all)
- run_vint; ret=$?
- echo "Main Vint: returned $ret"
- ((res |= ret))
- run_vader; ret=$?
- echo "Main Vader: returned $ret"
- ((res |= ret))
- ;;
- *)
- echo "Error: invalid type - '$g_type'" 1>&2
- exit 1
- esac
-
- return "$res"
-}
-
-
-run_test(){
- local -i res=0
-
- # Hi
- echo -en "Starting $(basename "$0") for VimWiki\n"
-
- # Hook ctrl-c or ctrl-z to stop tests
- trap exit 1 SIGINT SIGTERM
-
- # 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
-
- # WORK
- parse_argument "$@"; ((res |= $?))
- execute_test_argument; ((res |= $?))
-
- # Print ellapsed time (after calculate it)
- 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))
- echo -ne "Script $(basename "$0"), in $script_time, Returned -> $res\n\n"
-
- return "$res"
-}
-
-
if ! (return 0 2>/dev/null); then
run_test "$@"; exit $?
fi