Files
nuwiki/development/tests/test-config.sh
T

53 lines
1.6 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
#
# development/tests/test-config.sh — verify the Neovim client builds the
# exact `initialization_options` payload the server expects.
#
# Runs development/tests/test-config.lua under headless Neovim, which dumps
# the server-bound config (wiki_root, file_extension, syntax, log_level,
# wikis[*]) for a default and a sample scenario as `key=value` lines, then
# diffs the result against the shared golden config-expected.txt.
#
# The Vim harness (test-config-vim.sh) diffs against the SAME golden, so a
# green run of both proves Vim/Neovim config parity.
#
# Exit code: 0 when the payload matches the golden, 1 otherwise.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
TMP="$(mktemp -d -t nuwiki-config-test-XXXXXX)"
trap 'rm -rf "$TMP"' EXIT
log() { printf '\033[1;34m[config-test]\033[0m %s\n' "$*"; }
GOLDEN="$REPO_ROOT/development/tests/config-expected.txt"
OUT="$TMP/nvim-config.txt"
# No LSP server needed — we only inspect the payload the client would send.
INIT="$TMP/init.lua"
cat > "$INIT" <<EOF
vim.opt.runtimepath:prepend('$REPO_ROOT')
EOF
log 'running Neovim config harness…'
NUWIKI_CONFIG_OUT="$OUT" \
timeout 30 nvim --clean -u "$INIT" --headless \
-c "luafile $REPO_ROOT/development/tests/test-config.lua" \
>"$TMP/nvim.log" 2>&1 || true
if [[ ! -f "$OUT" ]]; then
echo 'config harness produced no output' >&2
echo '--- nvim log ---' >&2
cat "$TMP/nvim.log" >&2 || true
exit 1
fi
if diff -u "$GOLDEN" "$OUT"; then
log 'Neovim config payload matches golden ✓'
exit 0
fi
echo 'Neovim config payload DIVERGED from golden (see diff above)' >&2
exit 1