#!/usr/bin/env bash # # development/tests/test-coc-register-vim.sh — programmatic coc.nvim # registration for the Vim client. # # nuwiki#lsp#start() registers the language server with coc via coc#config so # users don't hand-maintain coc-settings.json. This harness stubs coc#config # (a real autoload/coc.vim on the runtimepath, since Vim's exists('*coc#config') # goes through the autoload mechanism) to record what nuwiki injects, then runs # test-coc-register-vim.vim and asserts the payload. # # 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[coc-register]\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-coc-test-XXXXXX)" trap 'rm -rf "$TMP"' EXIT # Stub coc#config as a real autoload function so exists('*coc#config') resolves # it. It records the last call into g:_recorded for the test to assert. mkdir -p "$TMP/stub/autoload" cat > "$TMP/stub/autoload/coc.vim" <<'EOF' function! coc#config(section, value) abort let g:_recorded = {'section': a:section, 'value': deepcopy(a:value)} endfunction EOF OUT="$TMP/coc.out" VIMRC="$TMP/vimrc" cat > "$VIMRC" <"$TMP/vim.log" 2>&1 || true if [[ ! -f "$OUT" ]]; then echo 'coc-registration 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 'coc registration OK ✓' exit 0