#!/usr/bin/env bash # # development/tests/test-calendar-vim.sh — calendar-vim integration harness (Vim). # # Exercises the pure-VimL diary hooks (nuwiki#diary#calendar_action / # nuwiki#diary#calendar_sign) plus plugin/nuwiki.vim's auto-wiring of # g:calendar_action / g:calendar_sign. A stub calendar-vim is placed on the # runtimepath so :Calendar exists and the hooks start at calendar-vim's own # defaults — the exact state nuwiki must detect and override. # # Two runs: # 1. default → integration ON, hooks rewired, diary paths from wiki root # 2. opt-out → g:nuwiki_use_calendar=0 / g:nuwiki_no_calendar=1 leave # calendar-vim's defaults untouched # # No LSP binary is needed — the diary hooks are entirely client-side VimL. # Exit code: 0 when all assertions pass, 1 otherwise. Skips (0) without vim. set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" TMP="$(mktemp -d -t nuwiki-calendar-vim-test-XXXXXX)" trap 'rm -rf "$TMP"' EXIT log() { printf '\033[1;34m[calendar-vim]\033[0m %s\n' "$*"; } if ! command -v vim >/dev/null 2>&1; then log 'vim not installed — skipping' exit 0 fi # --- Scratch wiki with one seeded diary entry (2026-05-30) ---------------- WIKI="$TMP/wiki" mkdir -p "$WIKI/diary" echo "= index =" > "$WIKI/index.wiki" echo "= 2026-05-30 =" > "$WIKI/diary/2026-05-30.wiki" # --- Stub calendar-vim ---------------------------------------------------- # Mimics the real plugin closely enough for detection + the override path: # defines :Calendar and seeds calendar-vim's default hook names. CAL="$TMP/calendar-vim" mkdir -p "$CAL/plugin" "$CAL/autoload" cat > "$CAL/plugin/calendar.vim" <<'EOF' if exists('g:loaded_calendar_stub') | finish | endif let g:loaded_calendar_stub = 1 let g:calendar_action = get(g:, 'calendar_action', 'calendar#diary') let g:calendar_sign = get(g:, 'calendar_sign', 'calendar#sign') command! -nargs=* Calendar echo 'stub calendar' EOF cat > "$CAL/autoload/calendar.vim" <<'EOF' function! calendar#open(...) abort endfunction function! calendar#diary(...) abort endfunction function! calendar#sign(...) abort return 0 endfunction EOF run_harness() { local label="$1" vimrc="$2" harness="$3" local results="$TMP/results-$label.txt" log "running $label harness…" NUWIKI_CALENDAR_RESULTS="$results" \ NUWIKI_CALENDAR_WIKI="$WIKI" \ timeout 30 vim -e -s -u "$vimrc" -c "edit $WIKI/index.wiki" \ -c "source $harness" "$TMP/$label.log" 2>&1 || true if [[ ! -f "$results" ]]; then echo "calendar $label harness produced no output" >&2 echo "--- vim log ---" >&2 cat "$TMP/$label.log" >&2 || true return 1 fi cat "$results" grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$results" } # --- Run 1: default (integration ON) -------------------------------------- VIMRC="$TMP/vimrc" cat > "$VIMRC" <