summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-09-10 13:19:08 +0100
committerw0rp <devw0rp@gmail.com>2017-09-10 13:19:08 +0100
commitc4ad92e458f51ce849baed3b628fbd2f43303ace (patch)
treebb199b6cf77dddf906f4ef64fadabe86229ce37a /test
parent18a7d32c4cc77d0eaa9ff860f86a307d0baafa09 (diff)
downloadale-c4ad92e458f51ce849baed3b628fbd2f43303ace.zip
Move scripts for tests into the test directory, and do not export the Batch script for running tests
Diffstat (limited to 'test')
-rwxr-xr-xtest/script/check-supported-tools-tables68
-rwxr-xr-xtest/script/custom-checks92
2 files changed, 160 insertions, 0 deletions
diff --git a/test/script/check-supported-tools-tables b/test/script/check-supported-tools-tables
new file mode 100755
index 00000000..842d431b
--- /dev/null
+++ b/test/script/check-supported-tools-tables
@@ -0,0 +1,68 @@
+#!/bin/bash -eu
+
+# This script compares the table of supported tools in both the README file
+# and the doc/ale.txt file, so we can complain if they don't match up.
+
+# Find the start and end lines for the help section.
+ale_help_start_line="$( \
+ grep -m1 -n '^[0-9][0-9]*\. *Supported Languages' doc/ale.txt \
+ | sed 's/\([0-9]*\).*/\1/' \
+)"
+ale_help_section_size="$( \
+ tail -n +"$ale_help_start_line" doc/ale.txt \
+ | grep -m1 -n '================' \
+ | sed 's/\([0-9]*\).*/\1/' \
+)"
+# -- shellcheck complains about expr, but it works better.
+# shellcheck disable=SC2003
+ale_help_end_line="$(expr "$ale_help_start_line" + "$ale_help_section_size")"
+
+# Find the start and end lines for the same section in the README.
+readme_start_line="$( \
+ grep -m1 -n '^.*[0-9][0-9]*\. *Supported Languages' README.md \
+ | sed 's/\([0-9]*\).*/\1/' \
+)"
+readme_section_size="$( \
+ tail -n +"$readme_start_line" README.md \
+ | grep -m1 -n '^##.*Usage' \
+ | sed 's/\([0-9]*\).*/\1/' \
+)"
+# shellcheck disable=SC2003
+readme_end_line="$(expr "$readme_start_line" + "$readme_section_size")"
+
+doc_file="$(mktemp)"
+readme_file="$(mktemp)"
+
+sed -n "$ale_help_start_line,$ale_help_end_line"p doc/ale.txt \
+ | grep '\* .*: ' \
+ | sed 's/^*//' \
+ | sed 's/[`!^]\|([^)]*)//g' \
+ | sed 's/ *\([,:]\)/\1/g' \
+ | sed 's/ */ /g' \
+ | sed 's/^ *\| *$//g' \
+ | sed 's/^/ /' \
+ > "$doc_file"
+
+sed -n "$readme_start_line,$readme_end_line"p README.md \
+ | grep '| .* |' \
+ | sed '/^| Language\|^| ---/d' \
+ | sed 's/^|//' \
+ | sed 's/ \?|/:/' \
+ | sed 's/[`!^|]\|([^)]*)//g' \
+ | sed 's/\[\|\]//g' \
+ | sed 's/see.*\(,\|$\)/\1/g' \
+ | sed 's/ *\([,:]\)/\1/g' \
+ | sed 's/ */ /g' \
+ | sed 's/^ *\| *$//g' \
+ | sed 's/^/ /' \
+ | sed 's/ *-n flag//g' \
+ > "$readme_file"
+
+exit_code=0
+
+diff -U0 "$readme_file" "$doc_file" || exit_code=$?
+
+rm "$doc_file"
+rm "$readme_file"
+
+exit "$exit_code"
diff --git a/test/script/custom-checks b/test/script/custom-checks
new file mode 100755
index 00000000..aad16c9c
--- /dev/null
+++ b/test/script/custom-checks
@@ -0,0 +1,92 @@
+#!/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: ./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
+}
+
+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 ' \+$' '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 '==#' "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"
+
+exit $RETURN_CODE