test(git): add regression tests with a minimal headless harness

This commit is contained in:
2026-05-06 17:32:36 +02:00
parent e00a282194
commit d63c2ae578
4 changed files with 537 additions and 0 deletions
Executable
+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env bash
set -u
usage() {
cat <<EOF
Usage: ${0##*/} [--help] [TARGET ...]
Run Neovim integration tests. Each test file is invoked via
'nvim --headless --clean' with the project's runtimepath added.
With no targets, runs every test/**/*_test.lua. Each TARGET may be a
test file (test/git/util_test.lua) or a directory (test/git); a
directory expands to all _test.lua files beneath it.
Exit status is 0 if all tests passed, non-zero otherwise.
EOF
}
if [[ ${1:-} == --help || ${1:-} == -h ]]; then
usage
exit 0
fi
cd "$(dirname "$0")/.." || exit 1
ROOT=$PWD
if [[ -t 1 ]]; then
red=$'\033[31m'
green=$'\033[32m'
reset=$'\033[0m'
export TEST_COLOR=1
else
red=''
green=''
reset=''
fi
if [[ $# -gt 0 ]]; then
targets=("$@")
else
mapfile -d '' -t targets < <(find test -type f -name '*_test.lua' -print0 | sort -z)
fi
exit_code=0
total_passed=0
total_failed=0
for arg in "${targets[@]}"; do
if [[ -d "$arg" ]]; then
mapfile -d '' -t files < <(find "$arg" -type f -name '*_test.lua' -print0 | sort -z)
elif [[ -f "$arg" ]]; then
files=("$arg")
else
printf 'no such test target: %s\n' "$arg" >&2
exit_code=2
continue
fi
for f in "${files[@]}"; do
out=$(TEST_FILE_LABEL="$f" nvim --headless --clean \
-c "set rtp+=$ROOT" \
-c "lua package.path = package.path .. ';$ROOT/test/?.lua'" \
-c "luafile $f" \
-c "qa!" \
2>&1)
rc=$?
# Split the per-file results from any output.
results_line=$(printf '%s\n' "$out" | grep '^RESULTS ' | tail -1)
printf '%s\n' "$out" | grep -v '^RESULTS '
if [[ -n "$results_line" ]]; then
read -r _ p f_count <<<"$results_line"
total_passed=$((total_passed + p))
total_failed=$((total_failed + f_count))
fi
if [[ $rc -ne 0 ]]; then
exit_code=$rc
fi
done
done
printf '\n'
if [[ $total_failed -gt 0 ]]; then
printf '%s%d passed%s, %s%d failed%s\n' \
"$green" "$total_passed" "$reset" \
"$red" "$total_failed" "$reset"
else
printf '%s%d passed%s\n' "$green" "$total_passed" "$reset"
fi
exit "$exit_code"