67 lines
2.0 KiB
Bash
67 lines
2.0 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
#
|
||
|
|
# scripts/test-keymaps.sh — drive scripts/test-keymaps.lua under
|
||
|
|
# headless Neovim and report pass/fail per buffer-local keymap.
|
||
|
|
#
|
||
|
|
# The Lua harness needs a real LSP attachment (most keymaps dispatch
|
||
|
|
# `workspace/executeCommand`), so we:
|
||
|
|
# 1. ensure `bin/nuwiki-ls` is built (release),
|
||
|
|
# 2. spin up a scratch wiki under a temp dir,
|
||
|
|
# 3. invoke `nvim --headless` with a minimal init that loads the
|
||
|
|
# plugin + calls `setup()`, then sources the harness Lua.
|
||
|
|
#
|
||
|
|
# Exit code mirrors the harness: 0 on green, 1 on any failure.
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||
|
|
TMP="$(mktemp -d -t nuwiki-keymap-test-XXXXXX)"
|
||
|
|
trap 'rm -rf "$TMP"' EXIT
|
||
|
|
|
||
|
|
log() { printf '\033[1;34m[keymap-test]\033[0m %s\n' "$*"; }
|
||
|
|
|
||
|
|
# Build the LSP binary if missing.
|
||
|
|
BIN="$REPO_ROOT/bin/nuwiki-ls"
|
||
|
|
if [[ ! -x "$BIN" ]]; then
|
||
|
|
log 'building nuwiki-ls (release)…'
|
||
|
|
cargo build --release -p nuwiki-ls --manifest-path "$REPO_ROOT/Cargo.toml" >/dev/null
|
||
|
|
mkdir -p "$REPO_ROOT/bin"
|
||
|
|
ln -sf "$REPO_ROOT/target/release/nuwiki-ls" "$BIN"
|
||
|
|
fi
|
||
|
|
|
||
|
|
mkdir -p "$TMP/wiki"
|
||
|
|
echo "= seed =" > "$TMP/wiki/index.wiki"
|
||
|
|
|
||
|
|
INIT="$TMP/init.lua"
|
||
|
|
cat > "$INIT" <<EOF
|
||
|
|
-- Keep the harness self-contained; no plugin manager required.
|
||
|
|
vim.opt.runtimepath:prepend('$REPO_ROOT')
|
||
|
|
vim.g.nuwiki_binary_path = '$BIN'
|
||
|
|
require('nuwiki').setup({ wiki_root = '$TMP/wiki' })
|
||
|
|
EOF
|
||
|
|
|
||
|
|
RESULTS="$TMP/results.txt"
|
||
|
|
log "running harness…"
|
||
|
|
|
||
|
|
# `nvim --headless -u init.lua FILE +luafile …` — the harness's
|
||
|
|
# `vim.defer_fn` lets the LSP attach before tests fire, then writes
|
||
|
|
# the results file and exits. Output path is plumbed through env.
|
||
|
|
NUWIKI_KEYMAP_RESULTS="$RESULTS" \
|
||
|
|
nvim --clean -u "$INIT" --headless "$TMP/wiki/index.wiki" \
|
||
|
|
-c "luafile $REPO_ROOT/scripts/test-keymaps.lua" \
|
||
|
|
>"$TMP/nvim.log" 2>&1 || true
|
||
|
|
|
||
|
|
if [[ ! -f "$RESULTS" ]]; then
|
||
|
|
echo 'keymap test harness produced no output' >&2
|
||
|
|
echo '--- nvim log ---' >&2
|
||
|
|
cat "$TMP/nvim.log" >&2 || true
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
cat "$RESULTS"
|
||
|
|
|
||
|
|
if grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS"; then
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
exit 1
|