Skip to content

Commit a4731b4

Browse files
committed
[Tests] apply shellcheck on shell test files
and import tests outputs
1 parent d44851c commit a4731b4

File tree

10 files changed

+97
-99
lines changed

10 files changed

+97
-99
lines changed

tests/test.sh

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,37 @@ declare -a TEST_ARRAY=(
2222
"./test_bash/test_folding.sh"
2323
"./test_bash/test_textobject.sh"
2424
)
25+
MAIN_RETURN=0
2526
## now loop through the above array
2627
set +e
27-
for ONE_TEST in "${TEST_ARRAY[@]}"
28+
for TEST in "${TEST_ARRAY[@]}"
2829
do
29-
echo "Starting test: $ONE_TEST" | tee $VIM_OUTPUT_FILE
30-
bash "$ONE_TEST"
31-
echo -e "\n$ONE_TEST: Return code: $?" | tee $VIM_OUTPUT_FILE
30+
echo "Starting test: ${TEST}" | tee -a "${VIM_OUTPUT_FILE}"
31+
bash "${TEST}"
32+
R=$?
33+
MAIN_RETURN=$(( MAIN_RETURN + R ))
34+
echo -e "${TEST}: Return code: ${R}\n" | tee -a "${VIM_OUTPUT_FILE}"
3235
bash ./test_helpers_bash/test_prepare_between_tests.sh
3336
done
3437

35-
# Show errors:
36-
E1=$(grep -E "^E[0-9]+:" $VIM_OUTPUT_FILE)
37-
E2=$(grep -E "^Error" $VIM_OUTPUT_FILE)
38-
E3="$E1\n$E2"
39-
if [ "$E3" = "\n" ]
40-
then
41-
echo "No errors."
42-
else
43-
echo "Errors:"
44-
echo -e "$E3\n"
45-
fi
38+
echo "========================================================================="
39+
echo " RESULTS"
40+
echo "========================================================================="
4641

4742
# Show return codes.
48-
RETURN_CODES=$(cat $VIM_OUTPUT_FILE | grep -i "Return code")
43+
RETURN_CODES=$(grep -i "Return code" < "${VIM_OUTPUT_FILE}" | grep -v "Return code: 0")
4944
echo -e "${RETURN_CODES}"
5045

51-
# Exit the script with error if there are any return codes different from 0.
52-
if echo "${RETURN_CODES}" | grep -E "Return code: [1-9]" 1>/dev/null 2>/dev/null
53-
then
54-
exit 1
46+
# Show errors:
47+
E1=$(grep -E "^E[0-9]+:" "${VIM_OUTPUT_FILE}")
48+
E2=$(grep -Ei "^Error" "${VIM_OUTPUT_FILE}")
49+
if [[ "${MAIN_RETURN}" == "0" ]]; then
50+
echo "No errors."
5551
else
56-
exit 0
52+
echo "Errors:"
53+
echo -e "${E1}\n${E2}"
5754
fi
5855

56+
# Exit the script with error if there are any return codes different from 0.
57+
exit ${MAIN_RETURN}
5958
# vim: set fileformat=unix filetype=sh wrap tw=0 :

tests/test_bash/test_autocommands.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ declare -a TEST_PYMODE_COMMANDS_ARRAY=(
1515
### FOR PINPOINT TESTING ### "./test_procedures_vimscript/pymoderun.vim"
1616
### FOR PINPOINT TESTING ### )
1717

18+
RETURN_CODE=0
19+
1820
## now loop through the above array
1921
set +e
2022
for ONE_PYMODE_COMMANDS_TEST in "${TEST_PYMODE_COMMANDS_ARRAY[@]}"
2123
do
22-
echo "Starting test: $0:$ONE_PYMODE_COMMANDS_TEST" | tee $VIM_OUTPUT_FILE
23-
RETURN_CODE=$(vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source $ONE_PYMODE_COMMANDS_TEST" $VIM_DISPOSABLE_PYFILE > /dev/null 2>&1)
24+
CONTENT="$(vim --clean -i NONE -u "${VIM_TEST_VIMRC}" -c "source ${ONE_PYMODE_COMMANDS_TEST}" "${VIM_DISPOSABLE_PYFILE}" 2>&1)"
2425

2526
### Enable the following to execute one test at a time.
2627
### FOR PINPOINT TESTING ### vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source $ONE_PYMODE_COMMANDS_TEST" $VIM_DISPOSABLE_PYFILE
2728
### FOR PINPOINT TESTING ### exit 1
2829

29-
RETURN_CODE=$?
30-
echo -e "\n$0:$ONE_PYMODE_COMMANDS_TEST: Return code: $RETURN_CODE" | tee $VIM_OUTPUT_FILE
30+
SUB_TEST_RETURN_CODE=$?
31+
echo -e "${CONTENT}" >> "${VIM_OUTPUT_FILE}"
32+
RETURN_CODE=$(( RETURN_CODE + SUB_TEST_RETURN_CODE ))
33+
echo -e "\tSubTest: $0:${ONE_PYMODE_COMMANDS_TEST}: Return code: ${SUB_TEST_RETURN_CODE}" | tee -a "${VIM_OUTPUT_FILE}"
3134
bash ./test_helpers_bash/test_prepare_between_tests.sh
3235
done
3336

37+
exit ${RETURN_CODE}
3438
# vim: set fileformat=unix filetype=sh wrap tw=0 :

tests/test_bash/test_autopep8.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
# Source file.
44
set +e
5-
RETURN_CODE=$(vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source ./test_procedures_vimscript/autopep8.vim" $VIM_DISPOSABLE_PYFILE > /dev/null 2>&1)
5+
CONTENT="$(vim --clean -i NONE -u "${VIM_TEST_VIMRC}" -c "source ./test_procedures_vimscript/autopep8.vim" "${VIM_DISPOSABLE_PYFILE}" 2>&1)"
66
RETURN_CODE=$?
7+
echo -e "${CONTENT}" >> "${VIM_OUTPUT_FILE}"
78
set -e
8-
exit $RETURN_CODE
99

10+
exit ${RETURN_CODE}
1011
# vim: set fileformat=unix filetype=sh wrap tw=0 :

tests/test_bash/test_folding.sh

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,24 @@
22

33
# Note: a solution with unix 'timeout' program was tried but it was unsuccessful. The problem with folding 4 is that in the case of a crash one expects the folding to just stay in an infinite loop, thus never existing with error. An improvement is suggested to this case.
44

5-
# Source file.
6-
set +e
7-
source ./test_helpers_bash/test_prepare_between_tests.sh
8-
vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source ./test_procedures_vimscript/folding1.vim" $VIM_DISPOSABLE_PYFILE > /dev/null
9-
R1=$?
10-
source ./test_helpers_bash/test_prepare_between_tests.sh
11-
vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source ./test_procedures_vimscript/folding2.vim" $VIM_DISPOSABLE_PYFILE > /dev/null
12-
R2=$?
13-
source ./test_helpers_bash/test_prepare_between_tests.sh
14-
# TODO: enable folding3.vim script back.
15-
# vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source ./test_procedures_vimscript/folding3.vim" $VIM_DISPOSABLE_PYFILE > /dev/null
16-
# R3=$?
17-
source ./test_helpers_bash/test_prepare_between_tests.sh
18-
vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source ./test_procedures_vimscript/folding4.vim" $VIM_DISPOSABLE_PYFILE > /dev/null
19-
R4=$?
20-
set -e
5+
declare -a TEST_PYMODE_FOLDING_TESTS_ARRAY=(
6+
"./test_procedures_vimscript/folding1.vim"
7+
"./test_procedures_vimscript/folding2.vim"
8+
# "./test_procedures_vimscript/folding3.vim"
9+
"./test_procedures_vimscript/folding4.vim"
10+
)
11+
12+
RETURN_CODE=0
2113

22-
if [[ "$R1" -ne 0 ]]
23-
then
24-
exit 1
25-
elif [[ "$R2" -ne 0 ]]
26-
then
27-
exit 2
28-
# elif [[ "$R3" -ne 0 ]]
29-
# then
30-
# exit 3
31-
elif [[ "$R4" -ne 0 ]]
32-
then
33-
exit 4
34-
fi
14+
set +e
15+
for SUB_TEST in "${TEST_PYMODE_FOLDING_TESTS_ARRAY[@]}"; do
16+
CONTENT="$(vim --clean -i NONE -u "${VIM_TEST_VIMRC}" -c "source ${SUB_TEST}" "${VIM_DISPOSABLE_PYFILE}" 2>&1)"
17+
SUB_TEST_RETURN_CODE=$?
18+
echo -e "${CONTENT}" >> "${VIM_OUTPUT_FILE}"
19+
RETURN_CODE=$(( RETURN_CODE + SUB_TEST_RETURN_CODE ))
20+
echo -e "\tSubTest: $0:${SUB_TEST}: Return code: ${SUB_TEST_RETURN_CODE}" | tee -a "${VIM_OUTPUT_FILE}"
21+
bash ./test_helpers_bash/test_prepare_between_tests.sh
22+
done
3523

24+
exit ${RETURN_CODE}
3625
# vim: set fileformat=unix filetype=sh wrap tw=0 :

tests/test_bash/test_pymodelint.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
# Source file.
77
set +e
8-
vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source ./test_procedures_vimscript/pymodelint.vim" $VIM_DISPOSABLE_PYFILE
9-
# RETURN_CODE=$(vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source ./test_procedures_vimscript/pymodeversion.vim" $VIM_DISPOSABLE_PYFILE > /dev/null 2>&1)
10-
# RETURN_CODE=$?
8+
# vim --clean -i NONE -u "${VIM_TEST_VIMRC}" -c "source ./test_procedures_vimscript/pymodelint.vim" "${VIM_DISPOSABLE_PYFILE}" >> "${VIM_OUTPUT_FILE}" 2>&1
9+
CONTENT="$(vim --clean -i NONE -u "${VIM_TEST_VIMRC}" -c "source ./test_procedures_vimscript/pymodeversion.vim" "${VIM_DISPOSABLE_PYFILE}" 2>&1)"
10+
RETURN_CODE=$?
11+
echo -e "${CONTENT}" >> "${VIM_OUTPUT_FILE}"
1112
set -e
12-
# exit $RETURN_CODE
1313

14+
exit ${RETURN_CODE}
1415
# vim: set fileformat=unix filetype=sh wrap tw=0 :

tests/test_bash/test_textobject.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
# Source file.
44
set +e
5+
# shellcheck source=../test_helpers_bash/test_prepare_between_tests.sh
56
source ./test_helpers_bash/test_prepare_between_tests.sh
6-
vim --clean -i NONE -u $VIM_TEST_VIMRC -c "source ./test_procedures_vimscript/textobject.vim" $VIM_DISPOSABLE_PYFILE > /dev/null
7-
R1=$?
7+
CONTENT="$(vim --clean -i NONE -u "${VIM_TEST_VIMRC}" -c "source ./test_procedures_vimscript/textobject.vim" "${VIM_DISPOSABLE_PYFILE}" 2>&1)"
8+
RETURN_CODE=$?
9+
echo -e "${CONTENT}" >> "${VIM_OUTPUT_FILE}"
810
set -e
911

10-
if [[ "$R1" -ne 0 ]]
11-
then
12-
exit 1
13-
fi
14-
12+
exit ${RETURN_CODE}
1513
# vim: set fileformat=unix filetype=sh wrap tw=0 :
Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#! /bin/bash
22

33
# Create minimal vimrc.
4-
echo -e "syntax on\nfiletype plugin indent on\nset nocompatible" >> $VIM_TEST_VIMRC
5-
echo "call has('python3')" >> $VIM_TEST_VIMRC
6-
echo "set paste" >> $VIM_TEST_VIMRC
7-
echo "set shortmess=at" >> $VIM_TEST_VIMRC
8-
echo "set cmdheight=10" >> $VIM_TEST_VIMRC
9-
echo "set ft=python" >> $VIM_TEST_VIMRC
10-
echo "set shell=bash" >> $VIM_TEST_VIMRC
11-
echo "set noswapfile" >> $VIM_TEST_VIMRC
12-
echo "set backupdir=" >> $VIM_TEST_VIMRC
13-
echo "set undodir=" >> $VIM_TEST_VIMRC
14-
echo "set viewdir=" >> $VIM_TEST_VIMRC
15-
echo "set directory=" >> $VIM_TEST_VIMRC
16-
echo -e "set runtimepath=" >> $VIM_TEST_VIMRC
17-
echo -e "set runtimepath+=$(dirname $PWD)\n" >> $VIM_TEST_VIMRC
18-
echo -e "set packpath+=/tmp\n" >> $VIM_TEST_VIMRC
19-
# echo -e "redir! >> $VIM_OUTPUT_FILE\n" >> $VIM_TEST_VIMRC
20-
echo -e "set verbosefile=$VIM_OUTPUT_FILE\n" >> $VIM_TEST_VIMRC
21-
echo -e "let g:pymode_debug = 1" >> $VIM_TEST_VIMRC
22-
23-
echo "set nomore" >> $VIM_TEST_VIMRC
24-
25-
4+
cat <<-EOF >> "${VIM_TEST_VIMRC}"
5+
syntax on
6+
filetype plugin indent on
7+
set nocompatible
8+
call has('python3')
9+
set paste
10+
set shortmess=at
11+
set cmdheight=10
12+
set ft=python
13+
set shell=bash
14+
set noswapfile
15+
set backupdir=
16+
set undodir=
17+
set viewdir=
18+
set directory=
19+
set runtimepath=
20+
set runtimepath+="$(dirname "${PWD}")"
21+
set packpath+=/tmp
22+
" redir! >> "${VIM_OUTPUT_FILE}"
23+
set verbosefile="${VIM_OUTPUT_FILE}"
24+
let g:pymode_debug = 1
25+
set nomore
26+
EOF
2627
# vim: set fileformat=unix filetype=sh wrap tw=0 :

tests/test_helpers_bash/test_prepare_between_tests.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# Prepare tests.
44
set +e
5-
if [ -f $VIM_DISPOSABLE_PYFILE ]; then
6-
rm $VIM_DISPOSABLE_PYFILE
5+
if [ -f "${VIM_DISPOSABLE_PYFILE}" ]; then
6+
rm "${VIM_DISPOSABLE_PYFILE}"
77
fi
8-
export VIM_DISPOSABLE_PYFILE=`mktemp /tmp/pymode.tmpfile.XXXXXXXXXX.py`
8+
VIM_DISPOSABLE_PYFILE="$(mktemp /tmp/pymode.tmpfile.XXXXXXXXXX.py)"
9+
export VIM_DISPOSABLE_PYFILE
910
set -e
10-
touch $VIM_DISPOSABLE_PYFILE
11+
touch "${VIM_DISPOSABLE_PYFILE}"
1112

1213
# vim: set fileformat=unix filetype=sh wrap tw=0 :

tests/test_helpers_bash/test_prepare_once.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
# Prepare tests.
44
set +e
5-
rm $VIM_OUTPUT_FILE $VIM_TEST_VIMRC $VIM_TEST_PYMODECOMMANDS $VIM_DISPOSABLE_PYFILE 2&>/dev/null
5+
rm "${VIM_OUTPUT_FILE}" "${VIM_TEST_VIMRC}" "${VIM_TEST_PYMODECOMMANDS}" "${VIM_DISPOSABLE_PYFILE}" 2&>/dev/null
66
rm /tmp/*pymode* 2&>/dev/null
77
rm -rf /tmp/pack
88
mkdir -p /tmp/pack/test_plugins/start
9-
ln -s $(dirname $(pwd)) /tmp/pack/test_plugins/start/
9+
ln -s "$(dirname "$(pwd)")" /tmp/pack/test_plugins/start/
1010
set -e
1111

1212
# vim: set fileformat=unix filetype=sh wrap tw=0 :

tests/test_helpers_bash/test_variables.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
# Define variables for common test scripts.
44

55
# Set variables.
6-
export VIM_DISPOSABLE_PYFILE=`mktemp /tmp/pymode.tmpfile.XXXXXXXXXX.py`
7-
export VIM_OUTPUT_FILE=/tmp/pymode.out
8-
export VIM_TEST_VIMRC=/tmp/pymode_vimrc
9-
export VIM_TEST_PYMODECOMMANDS=/tmp/pymode_commands.txt
6+
VIM_DISPOSABLE_PYFILE="$(mktemp /tmp/pymode.tmpfile.XXXXXXXXXX.py)"
7+
export VIM_DISPOSABLE_PYFILE
8+
VIM_OUTPUT_FILE=/tmp/pymode.out
9+
export VIM_OUTPUT_FILE
10+
VIM_TEST_VIMRC=/tmp/pymode_vimrc
11+
export VIM_TEST_VIMRC
12+
VIM_TEST_PYMODECOMMANDS=/tmp/pymode_commands.txt
13+
export VIM_TEST_PYMODECOMMANDS
1014

1115
# vim: set fileformat=unix filetype=sh wrap tw=0 :

0 commit comments

Comments
 (0)