diff options
-rwxr-xr-x | run-tests | 83 | ||||
-rwxr-xr-x | test/script/custom-checks | 137 | ||||
-rwxr-xr-x | test/script/custom-linting-rules | 95 | ||||
-rwxr-xr-x | test/script/run-vader-tests | 7 | ||||
-rwxr-xr-x | test/script/run-vint | 18 |
5 files changed, 183 insertions, 157 deletions
@@ -11,7 +11,6 @@ current_image_id=d5a1b5915b09 image=w0rp/ale -docker_flags=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$image") exit_code=0 tests='test/*.vader test/*/*.vader test/*/*/*.vader test/*/*/*.vader' @@ -49,6 +48,12 @@ while [ $# -ne 0 ]; do run_vint=0 shift ;; + --vint-only) + run_vim_tests=0 + run_neovim_tests=0 + run_custom_checks=0 + shift + ;; --no-custom-checks) run_custom_checks=0 shift @@ -88,86 +93,18 @@ docker images -q w0rp/ale | grep "^$current_image_id" > /dev/null \ for vim in $(docker run --rm "$image" ls /vim-build/bin | grep '^neovim\|^vim' ); do if [[ $vim =~ ^neovim ]] && ((run_neovim_tests)); then - test/script/run-vader-tests $quiet_flag $verbose_flag "$vim" "$tests" + test/script/run-vader-tests $quiet_flag $verbose_flag "$vim" "$tests" || exit_code=$? elif ((run_vim_tests)); then - test/script/run-vader-tests $quiet_flag $verbose_flag "$vim" "$tests" + test/script/run-vader-tests $quiet_flag $verbose_flag "$vim" "$tests" || exit_code=$? fi done if ((run_vint)); then - echo '========================================' - echo 'Running Vint to lint our code' - echo '========================================' - echo 'Vint warnings/errors follow:' - echo - - set -o pipefail - docker run -a stdout "${docker_flags[@]}" vint -s . || exit_code=$? - set +o pipefail - echo + test/script/run-vint || exit_code=$? fi if ((run_custom_checks)); then - echo '========================================' - echo 'Running custom checks' - echo '========================================' - echo 'Custom warnings/errors follow:' - echo - - set -o pipefail - docker run -a stdout "${docker_flags[@]}" test/script/custom-checks . || exit_code=$? - set +o pipefail - echo - - echo '========================================' - echo 'Checking for duplicate tags' - echo '========================================' - echo 'Duplicate tags follow:' - echo - - grep --exclude=tags -roh '\*.*\*$' doc | sort | uniq -d || exit_code=$? - - echo '========================================' - echo 'Checking for invalid tag references' - echo '========================================' - echo 'Invalid tag references tags follow:' - echo - - tag_regex='[gb]\?:\?\(ale\|ALE\)[a-zA-Z_\-]\+' - - # Grep for tags and references, and complain if we find a reference without - # a tag for the reference. Only our tags will be included. - diff -u \ - <(grep --exclude=tags -roh "\*$tag_regex\*" doc | sort -u | sed 's/*//g') \ - <(grep --exclude=tags -roh "|$tag_regex|" doc | sort -u | sed 's/|//g') \ - | grep '^+[^+]' && exit_code=1 - - echo '========================================' - echo 'diff README.md and doc/ale.txt tables' - echo '========================================' - echo 'Differences follow:' - echo - - test/script/check-supported-tools-tables || exit_code=$? - - echo '========================================' - echo 'Look for badly aligned doc tags' - echo '========================================' - echo 'Badly aligned tags follow:' - echo - - # Documentation tags need to be aligned to the right margin, so look for - # tags which aren't at the right margin. - grep ' \*[^*]\+\*$' doc/ -r \ - | awk '{ sep = index($0, ":"); if (length(substr($0, sep + 1 )) < 79) { print } }' \ - | grep . && exit_code=1 - - echo '========================================' - echo 'Look for table of contents issues' - echo '========================================' - echo - - test/script/check-toc || exit_code=$? + test/script/custom-checks || exit_code=$? fi exit $exit_code diff --git a/test/script/custom-checks b/test/script/custom-checks index e2c906b3..791053d4 100755 --- a/test/script/custom-checks +++ b/test/script/custom-checks @@ -1,95 +1,68 @@ #!/bin/bash -eu -# This Bash script implements custom sanity checks for scripts beyond what -# Vint covers, which are easy to check with regex. +exit_code=0 +image=w0rp/ale +docker_flags=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$image") -# A flag for automatically fixing some errors. -FIX_ERRORS=0 -RETURN_CODE=0 +echo '========================================' +echo 'Running custom linting rules' +echo '========================================' +echo 'Custom warnings/errors follow:' +echo -function print_help() { - echo "Usage: ./custom-checks [--fix] [DIRECTORY]" 1>&2 - echo 1>&2 - echo " -h, --help Print this help text" 1>&2 - echo " --fix Automatically fix some errors" 1>&2 - exit 1 -} +set -o pipefail +docker run -a stdout "${docker_flags[@]}" test/script/custom-linting-rules . || exit_code=$? +set +o pipefail +echo -while [ $# -ne 0 ]; do - case $1 in - -h) ;& --help) - print_help - ;; - --fix) - FIX_ERRORS=1 - shift - ;; - --) - shift - break - ;; - -?*) - echo "Invalid argument: $1" 1>&2 - exit 1 - ;; - *) - break - ;; - esac -done +echo '========================================' +echo 'Checking for duplicate tags' +echo '========================================' +echo 'Duplicate tags follow:' +echo -if [ $# -eq 0 ] || [ -z "$1" ]; then - print_help -fi +grep --exclude=tags -roh '\*.*\*$' doc | sort | uniq -d || exit_code=$? -shopt -s globstar +echo '========================================' +echo 'Checking for invalid tag references' +echo '========================================' +echo 'Invalid tag references tags follow:' +echo -directories=("$@") +tag_regex='[gb]\?:\?\(ale\|ALE\)[a-zA-Z_\-]\+' -check_errors() { - regex="$1" - message="$2" +# Grep for tags and references, and complain if we find a reference without +# a tag for the reference. Only our tags will be included. +diff -u \ + <(grep --exclude=tags -roh "\*$tag_regex\*" doc | sort -u | sed 's/*//g') \ + <(grep --exclude=tags -roh "|$tag_regex|" doc | sort -u | sed 's/|//g') \ + | grep '^+[^+]' && exit_code=1 - for directory in "${directories[@]}"; do - while IFS= read -r match; do - RETURN_CODE=1 - echo "$match $message" - done < <(grep -n "$regex" "$directory"/**/*.vim \ - | grep -v 'no-custom-checks' \ - | grep -o '^[^:]\+:[0-9]\+' \ - | sed 's:^\./::') - done -} +echo '========================================' +echo 'diff README.md and doc/ale.txt tables' +echo '========================================' +echo 'Differences follow:' +echo -if (( FIX_ERRORS )); then - for directory in "${directories[@]}"; do - sed -i "s/^\(function.*)\) *$/\1 abort/" "$directory"/**/*.vim - sed -i "s/shellescape(/ale#Escape(/" "$directory"/**/*.vim - sed -i 's/==#/is#/g' "$directory"/**/*.vim - sed -i 's/==?/is?/g' "$directory"/**/*.vim - sed -i 's/!=#/isnot#/g' "$directory"/**/*.vim - sed -i 's/!=?/isnot?/g' "$directory"/**/*.vim - done -fi +test/script/check-supported-tools-tables || exit_code=$? -check_errors \ - '^function.*) *$' \ - 'Function without abort keyword (See :help except-compat)' -check_errors '^function[^!]' 'function without !' -check_errors ' \+$' 'Trailing whitespace' -check_errors '^ * end\?i\? *$' 'Write endif, not en, end, or endi' -check_errors '^ [^ ]' 'Use four spaces, not two spaces' -check_errors $'\t' 'Use four spaces, not tabs' -# This check should prevent people from using a particular inconsistent name. -check_errors 'let g:ale_\w\+_\w\+_args =' 'Name your option g:ale_<filetype>_<lintername>_options instead' -check_errors 'shellescape(' 'Use ale#Escape instead of shellescape' -check_errors 'simplify(' 'Use ale#path#Simplify instead of simplify' -check_errors "expand(['\"]%" "Use expand('#' . a:buffer . '...') instead. You might get a filename for the wrong buffer." -check_errors 'getcwd()' "Do not use getcwd(), as it could run from the wrong buffer. Use expand('#' . a:buffer . ':p:h') instead." -check_errors '==#' "Use 'is#' instead of '==#'. 0 ==# 'foobar' is true" -check_errors '==?' "Use 'is?' instead of '==?'. 0 ==? 'foobar' is true" -check_errors '!=#' "Use 'isnot#' instead of '!=#'. 0 !=# 'foobar' is false" -check_errors '!=?' "Use 'isnot?' instead of '!=?'. 0 !=? 'foobar' is false" -check_errors '^ *:\?echo' "Stray echo line. Use \`execute echo\` if you want to echo something" +echo '========================================' +echo 'Look for badly aligned doc tags' +echo '========================================' +echo 'Badly aligned tags follow:' +echo -exit $RETURN_CODE +# Documentation tags need to be aligned to the right margin, so look for +# tags which aren't at the right margin. +grep ' \*[^*]\+\*$' doc/ -r \ + | awk '{ sep = index($0, ":"); if (length(substr($0, sep + 1 )) < 79) { print } }' \ + | grep . && exit_code=1 + +echo '========================================' +echo 'Look for table of contents issues' +echo '========================================' +echo + +test/script/check-toc || exit_code=$? + +exit $exit_code diff --git a/test/script/custom-linting-rules b/test/script/custom-linting-rules new file mode 100755 index 00000000..ef6d792f --- /dev/null +++ b/test/script/custom-linting-rules @@ -0,0 +1,95 @@ +#!/bin/bash -eu + +# This Bash script implements custom sanity checks for scripts beyond what +# Vint covers, which are easy to check with regex. + +# A flag for automatically fixing some errors. +FIX_ERRORS=0 +RETURN_CODE=0 + +function print_help() { + echo "Usage: test/script/custom-linting-rules [--fix] [DIRECTORY]" 1>&2 + echo 1>&2 + echo " -h, --help Print this help text" 1>&2 + echo " --fix Automatically fix some errors" 1>&2 + exit 1 +} + +while [ $# -ne 0 ]; do + case $1 in + -h) ;& --help) + print_help + ;; + --fix) + FIX_ERRORS=1 + shift + ;; + --) + shift + break + ;; + -?*) + echo "Invalid argument: $1" 1>&2 + exit 1 + ;; + *) + break + ;; + esac +done + +if [ $# -eq 0 ] || [ -z "$1" ]; then + print_help +fi + +shopt -s globstar + +directories=("$@") + +check_errors() { + regex="$1" + message="$2" + + for directory in "${directories[@]}"; do + while IFS= read -r match; do + RETURN_CODE=1 + echo "$match $message" + done < <(grep -n "$regex" "$directory"/**/*.vim \ + | grep -v 'no-custom-checks' \ + | grep -o '^[^:]\+:[0-9]\+' \ + | sed 's:^\./::') + done +} + +if (( FIX_ERRORS )); then + for directory in "${directories[@]}"; do + sed -i "s/^\(function.*)\) *$/\1 abort/" "$directory"/**/*.vim + sed -i "s/shellescape(/ale#Escape(/" "$directory"/**/*.vim + sed -i 's/==#/is#/g' "$directory"/**/*.vim + sed -i 's/==?/is?/g' "$directory"/**/*.vim + sed -i 's/!=#/isnot#/g' "$directory"/**/*.vim + sed -i 's/!=?/isnot?/g' "$directory"/**/*.vim + done +fi + +check_errors \ + '^function.*) *$' \ + 'Function without abort keyword (See :help except-compat)' +check_errors '^function[^!]' 'function without !' +check_errors ' \+$' 'Trailing whitespace' +check_errors '^ * end\?i\? *$' 'Write endif, not en, end, or endi' +check_errors '^ [^ ]' 'Use four spaces, not two spaces' +check_errors $'\t' 'Use four spaces, not tabs' +# This check should prevent people from using a particular inconsistent name. +check_errors 'let g:ale_\w\+_\w\+_args =' 'Name your option g:ale_<filetype>_<lintername>_options instead' +check_errors 'shellescape(' 'Use ale#Escape instead of shellescape' +check_errors 'simplify(' 'Use ale#path#Simplify instead of simplify' +check_errors "expand(['\"]%" "Use expand('#' . a:buffer . '...') instead. You might get a filename for the wrong buffer." +check_errors 'getcwd()' "Do not use getcwd(), as it could run from the wrong buffer. Use expand('#' . a:buffer . ':p:h') instead." +check_errors '==#' "Use 'is#' instead of '==#'. 0 ==# 'foobar' is true" +check_errors '==?' "Use 'is?' instead of '==?'. 0 ==? 'foobar' is true" +check_errors '!=#' "Use 'isnot#' instead of '!=#'. 0 !=# 'foobar' is false" +check_errors '!=?' "Use 'isnot?' instead of '!=?'. 0 !=? 'foobar' is false" +check_errors '^ *:\?echo' "Stray echo line. Use \`execute echo\` if you want to echo something" + +exit $RETURN_CODE diff --git a/test/script/run-vader-tests b/test/script/run-vader-tests index d28e1987..d5daec29 100755 --- a/test/script/run-vader-tests +++ b/test/script/run-vader-tests @@ -7,6 +7,7 @@ green='\033[0;32m' nc='\033[0m' verbose=0 quiet=0 +exit_code=0 while [ $# -ne 0 ]; do case $1 in @@ -109,12 +110,14 @@ if [[ $vim =~ ^neovim ]]; then set -o pipefail docker run -it -e VADER_OUTPUT_FILE=/dev/stderr "${docker_flags[@]}" \ "/vim-build/bin/$vim" -u test/vimrc \ - --headless "+Vader! $tests" | filter-vader-output | color-vader-output + --headless "+Vader! $tests" | filter-vader-output | color-vader-output || exit_code=$? set +o pipefail else 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 + "+Vader! $tests" 2>&1 | filter-vader-output | color-vader-output || exit_code=$? set +o pipefail fi + +exit "$exit_code" diff --git a/test/script/run-vint b/test/script/run-vint new file mode 100755 index 00000000..e1140307 --- /dev/null +++ b/test/script/run-vint @@ -0,0 +1,18 @@ +#!/bin/bash -eu + +exit_code=0 +image=w0rp/ale +docker_flags=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$image") + +echo '========================================' +echo 'Running Vint to lint our code' +echo '========================================' +echo 'Vint warnings/errors follow:' +echo + +set -o pipefail +docker run -a stdout "${docker_flags[@]}" vint -s . || exit_code=$? +set +o pipefail +echo + +exit $exit_code |