Skip to content

Commit

Permalink
Reduce indentation test runner noise and add colour output
Browse files Browse the repository at this point in the history
  • Loading branch information
axvr committed Feb 4, 2025
1 parent 5b277db commit d8dc8a7
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions dev/do/test-indent
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

# Run Clojure.vim indentation tests.

# TODO: colour messages?
# TODO: option to enable/disable (Lua / Vim9script) versions.

C_GREEN='\033[1;32m'
C_RED='\033[1;31m'
C_YELLOW='\033[1;33m'
C_BLUE='\033[1;34m'
C_RESET='\033[0m'

log() { printf "$*$C_RESET\n"; }
logc() { log "$1$2"; }
succ() { logc "$C_GREEN" "$*"; }
warn() { logc "$C_YELLOW" "$*"; }
err() { logc "$C_RED" "$*"; }
info() { logc "$C_BLUE" "$*"; }
abort() { err "ABORT: $*"; exit 1; }

pushd "$(dirname "$0")/.."

if [ "$EDITOR" != 'vim' ] && [ "$EDITOR" != 'nvim' ]; then
echo 'ERROR: Set the "EDITOR" environment variable to "vim" or "nvim" and run again.'
exit 1
abort 'Set the "EDITOR" environment variable to "vim" or "nvim" and run again.'
fi

extra_opts=()
Expand All @@ -23,24 +36,22 @@ mkdir -p "$tmp_base_dir"
tmp_dir="$(mktemp --directory "$tmp_base_dir/XXXXXX")"
test_case_dir='tests'

test_pass() { PASSED+=("$1"); echo '::endgroup::'; }
test_pass() { PASSED+=("$1"); }
test_fail() {
FAILED+=("$1")
echo '::endgroup::'
echo "::error file=dev/$test_case_dir/$1/out.clj::Failed indent test case."
err "::error file=dev/$test_case_dir/$1/out.clj::Failed indent test case."
}
test_skip() {
SKIPPED+=("$1")
echo '::endgroup::'
echo "::warning file=dev/$test_case_dir/$1/out.clj::Skipped indent test case."
warn "::warning file=dev/$test_case_dir/$1/out.clj::Skipped indent test case."
}

run_test_case() {
test_case="$1"
in_file="$test_case_dir/$test_case/in.clj"
expected_file="$test_case_dir/$test_case/out.clj"

echo "::group::$EDITOR: $test_case"
info "> $EDITOR: $test_case"

if [ -f "$test_case_dir/$test_case/SKIP" ]; then
test_skip "$test_case"
Expand All @@ -56,7 +67,8 @@ run_test_case() {
test_cmd=('+normal! gg=G')
fi

"$EDITOR" "${extra_opts[@]}" --clean -EsNXnu test-vimrc.vim "${test_cmd[@]}" '+xall!' -- "$actual_file"
"$EDITOR" "${extra_opts[@]}" --clean -EsNXnu test-vimrc.vim \
"${test_cmd[@]}" '+xall!' -- "$actual_file"

diff --color=always -u "$expected_file" "$actual_file"

Expand All @@ -68,9 +80,10 @@ for tcase in $test_case_dir/*/; do
run_test_case "$(basename "$tcase")"
done

echo "passed: ${#PASSED[@]}, failed: ${#FAILED[@]}, skipped: ${#SKIPPED[@]}"
printf "passed: $C_GREEN%s$C_RESET, failed: $C_RED%s$C_RESET, skipped: $C_YELLOW%s$C_RESET\n" \
"${#PASSED[@]}" "${#FAILED[@]}" "${#SKIPPED[@]}"

# If none passed, or some failed, exit with error.
if [ ${#PASSED[@]} -eq 0 ] || [ ${#FAILED[@]} -gt 0 ]; then
exit 1
abort 'Failed test cases.'
fi

0 comments on commit d8dc8a7

Please sign in to comment.