Skip to content

Commit d8dc8a7

Browse files
committed
Reduce indentation test runner noise and add colour output
1 parent 5b277db commit d8dc8a7

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

dev/do/test-indent

+25-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@
22

33
# Run Clojure.vim indentation tests.
44

5-
# TODO: colour messages?
5+
# TODO: option to enable/disable (Lua / Vim9script) versions.
6+
7+
C_GREEN='\033[1;32m'
8+
C_RED='\033[1;31m'
9+
C_YELLOW='\033[1;33m'
10+
C_BLUE='\033[1;34m'
11+
C_RESET='\033[0m'
12+
13+
log() { printf "$*$C_RESET\n"; }
14+
logc() { log "$1$2"; }
15+
succ() { logc "$C_GREEN" "$*"; }
16+
warn() { logc "$C_YELLOW" "$*"; }
17+
err() { logc "$C_RED" "$*"; }
18+
info() { logc "$C_BLUE" "$*"; }
19+
abort() { err "ABORT: $*"; exit 1; }
620

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

923
if [ "$EDITOR" != 'vim' ] && [ "$EDITOR" != 'nvim' ]; then
10-
echo 'ERROR: Set the "EDITOR" environment variable to "vim" or "nvim" and run again.'
11-
exit 1
24+
abort 'Set the "EDITOR" environment variable to "vim" or "nvim" and run again.'
1225
fi
1326

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

26-
test_pass() { PASSED+=("$1"); echo '::endgroup::'; }
39+
test_pass() { PASSED+=("$1"); }
2740
test_fail() {
2841
FAILED+=("$1")
29-
echo '::endgroup::'
30-
echo "::error file=dev/$test_case_dir/$1/out.clj::Failed indent test case."
42+
err "::error file=dev/$test_case_dir/$1/out.clj::Failed indent test case."
3143
}
3244
test_skip() {
3345
SKIPPED+=("$1")
34-
echo '::endgroup::'
35-
echo "::warning file=dev/$test_case_dir/$1/out.clj::Skipped indent test case."
46+
warn "::warning file=dev/$test_case_dir/$1/out.clj::Skipped indent test case."
3647
}
3748

3849
run_test_case() {
3950
test_case="$1"
4051
in_file="$test_case_dir/$test_case/in.clj"
4152
expected_file="$test_case_dir/$test_case/out.clj"
4253

43-
echo "::group::$EDITOR: $test_case"
54+
info "> $EDITOR: $test_case"
4455

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

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

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

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

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

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

0 commit comments

Comments
 (0)