ddb9d0b916
s:resolve_index referenced an undefined `a:file` (a copy-paste leftover
from wiki_root_for, whose parameter is named a:file) inside the
buffer-owning-wiki loop. Any get_wikilocal() call with no explicit index
while a wiki buffer was current — i.e. the ftplugin BufRead path — hit
`E121: undefined variable a:file`. The local is `l:file`, and the
surrounding `!empty(l:file)` guard already covers emptiness, so the
clause was both wrong and redundant; removed it.
Add development/tests/test-vars-vim.{sh,vim} covering the shim:
per-wiki-index resolution, global-default fallback, out-of-range clamp,
the no-index owning-wiki path (direct guard for this E121), and the
single-wiki shorthand. Wired into CI. 14/14 pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
68 lines
1.8 KiB
Bash
Executable File
68 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# development/tests/test-vars-vim.sh — exercises the vimwiki compatibility
|
|
# shim (autoload/vimwiki/vars.vim) that third-party plugins (vimwiki-sync,
|
|
# vim-zettel) call via vimwiki#vars#get_wikilocal.
|
|
#
|
|
# Runs test-vars-vim.vim under headless Vim; that script writes PASS/FAIL
|
|
# lines to $NUWIKI_VARS_OUT. Covers per-wiki-index resolution, global
|
|
# fallback, out-of-range clamp, the no-index "owning wiki" path (the
|
|
# BufRead path that previously raised E121), and the single-wiki shorthand.
|
|
#
|
|
# Exit code: 0 when every check passes, 1 on any FAIL or missing output.
|
|
# Skips (exit 0) when vim is not installed.
|
|
|
|
set -euo pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
|
|
log() { printf '\033[1;34m[vars-vim]\033[0m %s\n' "$*"; }
|
|
|
|
if ! command -v vim >/dev/null 2>&1; then
|
|
log 'vim not installed — skipping'
|
|
exit 0
|
|
fi
|
|
|
|
TMP="$(mktemp -d -t nuwiki-vars-vim-test-XXXXXX)"
|
|
trap 'rm -rf "$TMP"' EXIT
|
|
|
|
DIR_A="$TMP/wiki_a"
|
|
DIR_B="$TMP/wiki_b"
|
|
mkdir -p "$DIR_A" "$DIR_B"
|
|
printf '= Home =\n' > "$DIR_A/index.wiki"
|
|
printf '= B =\n' > "$DIR_B/index.wiki"
|
|
|
|
OUT="$TMP/vars.out"
|
|
|
|
VIMRC="$TMP/vimrc"
|
|
cat > "$VIMRC" <<EOF
|
|
set nocompatible
|
|
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
|
EOF
|
|
|
|
log 'running Vim vars-shim harness…'
|
|
NUWIKI_VARS_OUT="$OUT" \
|
|
NUWIKI_VARS_DIR_A="$DIR_A" \
|
|
NUWIKI_VARS_DIR_B="$DIR_B" \
|
|
timeout 30 vim -e -s -u "$VIMRC" \
|
|
-c "source $REPO_ROOT/development/tests/test-vars-vim.vim" \
|
|
</dev/null >"$TMP/vim.log" 2>&1 || true
|
|
|
|
if [[ ! -f "$OUT" ]]; then
|
|
echo 'vars harness produced no output' >&2
|
|
echo '--- vim log ---' >&2
|
|
cat "$TMP/vim.log" >&2 || true
|
|
exit 1
|
|
fi
|
|
|
|
cat "$OUT"
|
|
PASSED="$(grep -c '^PASS ' "$OUT" || true)"
|
|
FAILED="$(grep -c '^FAIL ' "$OUT" || true)"
|
|
echo "SUMMARY: ${PASSED} passed, ${FAILED} failed"
|
|
|
|
if [[ "$FAILED" -ne 0 ]]; then
|
|
exit 1
|
|
fi
|
|
log 'vars shim OK ✓'
|
|
exit 0
|