87ba4c1764
Add headless harnesses covering the calendar-vim integration, wired into CI alongside the existing keymap/config suites: - test-calendar-vim.sh/.vim (+ -optout.vim): pure-VimL diary hooks (calendar_sign markers, calendar_action path resolution from wiki root, calendar window close), plugin/nuwiki.vim hook auto-wiring that overrides calendar-vim's defaults, and opt-out via g:nuwiki_use_calendar and g:nuwiki_no_calendar. Uses a stub calendar-vim on the runtimepath. - test-calendar.sh/.lua: Neovim setup() wiring + window-close under the real window API, and opt-out via use_calendar = false. Fixes surfaced by the suite: - diary.vim: new diary entries set filetype 'vimwiki' (was the raw extension, e.g. 'wiki'); the stray FileType autocmd also blocked the calendar window from closing. - init.lua: drop the redundant Neovim FileType autocmd (plugin/nuwiki.vim already wires both editors) and translate use_calendar=false into g:nuwiki_no_calendar so the opt-out actually disables wiring.
122 lines
4.1 KiB
Bash
Executable File
122 lines
4.1 KiB
Bash
Executable File
#!/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" </dev/null >"$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" <<EOF
|
|
set nocompatible
|
|
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
|
let &runtimepath .= ',$CAL'
|
|
let g:nuwiki_wiki_root = '$WIKI'
|
|
let g:nuwiki_file_extension = '.wiki'
|
|
let g:nuwiki_diary_rel_path = 'diary'
|
|
set hidden
|
|
filetype plugin indent on
|
|
syntax enable
|
|
EOF
|
|
|
|
# --- Run 2: opt-out via g:nuwiki_use_calendar = 0 -------------------------
|
|
VIMRC_OPTOUT="$TMP/vimrc-optout"
|
|
cat > "$VIMRC_OPTOUT" <<EOF
|
|
set nocompatible
|
|
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
|
let &runtimepath .= ',$CAL'
|
|
let g:nuwiki_use_calendar = 0
|
|
let g:nuwiki_wiki_root = '$WIKI'
|
|
filetype plugin indent on
|
|
syntax enable
|
|
EOF
|
|
|
|
# --- Run 3: opt-out via g:nuwiki_no_calendar = 1 --------------------------
|
|
VIMRC_NOCAL="$TMP/vimrc-nocal"
|
|
cat > "$VIMRC_NOCAL" <<EOF
|
|
set nocompatible
|
|
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
|
let &runtimepath .= ',$CAL'
|
|
let g:nuwiki_no_calendar = 1
|
|
let g:nuwiki_wiki_root = '$WIKI'
|
|
filetype plugin indent on
|
|
syntax enable
|
|
EOF
|
|
|
|
rc=0
|
|
run_harness 'default' "$VIMRC" "$REPO_ROOT/development/tests/test-calendar-vim.vim" || rc=1
|
|
run_harness 'optout-use' "$VIMRC_OPTOUT" "$REPO_ROOT/development/tests/test-calendar-vim-optout.vim" || rc=1
|
|
run_harness 'optout-no' "$VIMRC_NOCAL" "$REPO_ROOT/development/tests/test-calendar-vim-optout.vim" || rc=1
|
|
|
|
exit $rc
|