Skip to content

tests/vim: share the headless-Vim launcher; fold.bats; helper docs - #151

Merged
harleypig merged 3 commits into
masterfrom
test/vim-helper
Nov 4, 2026
Merged

harleypig merged 3 commits into
masterfrom
test/vim-helper

Conversation

@harleypig

@harleypig harleypig commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

The tests/vim half of #136. The tests/shell half landed in #141.

  • Shared launcher (tests/vim/helpers/vim.bash). All twelve Vim test files built the same environment and the same Vim command line themselves: HOME and the XDG directories in the test's temp directory, a PATH holding only a stub directory, and timeout 30 env -i … vim -N -u .vimrc -es. They now load one helper, following the shell half's load helpers/<name> pattern:

    • vim_fixture, called from setup, sets $repo, $vim, $vimrc, $home, $stubs (holding only sh), $report and the $vim_env array.
    • headless_vim [VAR=VALUE...] [--] [VIM ARGS...] runs Vim in that environment, with any extra variables taking precedence, and returns Vim's exit status.
    • vim_env_unset NAME... removes a variable for tests that need it unset (vimrc.bats unsets XDG_DOTVIM, xdg.bats unsets XDG_STATE_HOME and XDG_DATA_HOME).
    • with_node is the node tripwire stub, which coc.bats and load.bats each had a copy of.

    Each file's report.vim scaffolding and its own submodule check are left as they were. Their contents differ from file to file, so they are not a shared launcher.

  • oldfiles.bats → fold.bats (from Small tidy-ups: envsubstitute help quote, old shell-lint warnings, proselint config path #44). The file tests CustomFoldText() in the late fold.vim. Its name and header still referred to the deleted OLD_FILES/. The new name matches set.bats and maps.bats, and the header now says what the file checks.

  • .claude/TESTS.md gets a Shared helpers section saying where each suite's helpers live and naming both of them (v0.2.0).

Refs #44
Closes #136

For files added later: other tests/vim/*.bats files being written at the same time as this PR still carry their own copy of the launcher. Each one should switch to load helpers/vim and call vim_fixture/headless_vim once it and this PR have both merged.

Test plan

  • bats tests/vim with a fresh, empty TMPDIR: 75/75 ok, which is the same count as on master before the change. TMPDIR was still empty afterwards.
  • bats tests/shell with a fresh, empty TMPDIR: all ok, TMPDIR still empty afterwards.
  • shellcheck -s bash and shfmt -i 2 -s -bn -ci -sr -d (the repo's shfmt style) on the helper: both clean.
  • markdownlint (the CI image, pinned by digest) on .claude/TESTS.md: clean.

Testing evaluation

I ran this myself to the qa-tester's standard; there is no team-managed: sentinel.

  1. Verdict: already covered. The change is a behaviour-preserving refactor of the test harness, and the 75 existing tests are what cover it. The risk is that a test is still green but no longer able to fail, so each break below was checked for red after the refactor.
  2. Automatable: yes. bats, tests/vim/*.bats.
  3. Falsifiers. Each break was applied after the refactor, confirmed red, then restored:
    • .vimrc XDG_DOTVIM fallback pointed at /nowhere → vimrc.bats red in 3 tests (unset, empty, symlink). This shows vim_env_unset XDG_DOTVIM really leaves the variable unset.
    • vim_env_unset made a no-op → xdg.bats "unset, Vim uses the defaults" red.
    • headless_vim drops its extra VAR=VALUE args → xdg.bats "set, Vim uses them" red.
    • with_node stub left non-executable → coc.bats "with node" and "Tab at the start of a line" red.
    • Real PATH (host has node) in vim_env → coc.bats "without node, CoC … not loaded" red.
    • set foldtext= commented out in fold.vim → fold.bats red in all 3 tests.
    • algorithm:patience commented out in set.vim → set.bats red.
    • A call to an undefined function appended to set.vim → load.bats "starts with no error message" red in both tests (with and without node).
    • helptags.vim made to always rebuild → helptags.bats "tags newer … left alone" red.
    • shfmt --indent 2 → --indent 4 in the sh ftplugin → sh-ftplugin.bats red.
  4. Disposition: nothing new is owed. The falsifiers above were the work this PR needed.
  5. Entry-point reach: not applicable. This is test harness code, not a guard or a gate.

Manual verification

  1. From a checkout with submodules initialised (git submodule update --init) and BATS_LIB_PATH pointing at bats-support/bats-assert.
  2. Run d=$(mktemp -d); TMPDIR=$d bats tests/vim; ls -A "$d".
  3. Success: 1..75, every line ok, exit 0, and ls -A prints nothing.
  4. Failure looks like any not ok line, or a leftover entry in $d.
  5. Run: 1..75, 75 ok, 0 not ok, exit 0. The temp directory was left with 0 entries.

Review

opt-out: no named review skill (code-review or similar) ran on this test-only refactor. In its place, the falsifiers above stand as evidence, together with a self-review of the diff, which turned up the points below for a reviewer to check.

  • Behaviour change. vimrc.bats and xdg.bats now also get XDG_CONFIG_HOME and XDG_CACHE_HOME inside the temp directory. Before, they left both unset, which falls back to $home/.config and $home/.cache, also inside the temp directory. Neither file tests those two variables.
  • Argument parsing. headless_vim treats leading VAR=VALUE words as environment variables. A file argument containing = therefore has to come after --. statusline.bats and sh-ftplugin.bats already pass -- before their file paths.
  • What to check: whether report and home belong in vim_fixture. report is unused by helptags.bats and sh-ftplugin.bats, and has a SC2034 suppression with its reason. Also check whether moving with_node (two copies, not three) goes beyond the issue's "launcher".

Completion report

  1. Functionality works: met. All 75 tests pass, and the falsifiers above confirm the tests can still fail.
  2. Access model: not applicable. Test harness, no access surface.
  3. Permissions: not applicable, same reason.
  4. Audit logging: not applicable, same reason.
  5. Validation: not applicable. No input boundary.
  6. Errors handled: met. Vim's exit status is still returned to each caller, and each caller keeps its own || vim_status=$? or || true handling.
  7. Testing complete: met. See the testing evaluation above.
  8. Documentation: met. .claude/TESTS.md Shared helpers, the helper's own header, and the updated test-file headers.
  9. Completion report: this section.

Co-Authored-By: AI Agent noreply@harleypig.com

harleypig and others added 3 commits November 4, 2026 01:18
Every Vim test file built the same environment and Vim command line:
HOME and the XDG directories in the test's temp directory, a PATH holding
only a stub directory, and `vim -N -u .vimrc -es` under a 30-second
timeout. They now load helpers/vim.bash, which sets that up once
(vim_fixture), runs Vim in it (headless_vim), drops a variable a test
needs unset (vim_env_unset) and adds the node tripwire (with_node).

vimrc.bats and xdg.bats now also get XDG_CONFIG_HOME and XDG_CACHE_HOME
inside the temp directory, which they previously left unset; neither
tests those two.

Refs #136

Co-Authored-By: AI Agent <noreply@harleypig.com>
oldfiles.bats tests CustomFoldText() in the late fold.vim, and its name
and header still pointed at the OLD_FILES/ directory it was merged out
of, which is gone. It is fold.bats now, beside set.bats and maps.bats,
with a header saying what it checks.

Refs #44

Co-Authored-By: AI Agent <noreply@harleypig.com>
TESTS.md now says shared test code goes in each suite's helpers/
directory, loaded with `load`, and names the two there:
tests/shell/helpers/git-fixture.bash and tests/vim/helpers/vim.bash.

Refs #44

Co-Authored-By: AI Agent <noreply@harleypig.com>
@harleypig harleypig added this to the Pre-improvement milestone Nov 4, 2026
@harleypig
harleypig merged commit e60653e into master Nov 4, 2026
4 checks passed
harleypig added a commit that referenced this pull request Nov 4, 2026
…er (#155)

* fix(settings): CustomFoldText is script-local (#44)

The late fold.vim's fold-text function is now s:CustomFoldText(), and
'foldtext' is set with the s: form, which Vim (8.2.3908 and later) replaces
with the function's <SNR> name. tests/vim/fold.bats checks for that name
and that no global CustomFoldText() exists.

Co-Authored-By: AI Agent <noreply@harleypig.com>

* fix(settings): gutter toggles are script-local Normal-mode mappings (#44)

ToggleLineNumbers and its sibling ToggleSigns in the late gutter.vim are
now script-local, and <leader>ln and <leader>signs are nnoremap calls to
<SID> versions. The old recursive map also defined them in Visual and
Operator-pending mode, where the :call ran once per selected line. The
docs name no mode for either, so they are unchanged.

tests/vim/tidy.bats checks the mappings' modes, that neither function is
global, and that each toggle still cycles as documented.

Co-Authored-By: AI Agent <noreply@harleypig.com>

* docs: drop the coc-ale-setup bullet on removed completion branches (#44)

The <Tab> and <C-Space> mappings in the late coc.vim no longer check for
a completion plugin that is not installed (removed in #152 - coc.vim
tidy-ups), so the bullet saying they do is gone.

Co-Authored-By: AI Agent <noreply@harleypig.com>

* test(vim): colors, ale-settings and tidy use the shared launcher (#44)

The three Vim test files added alongside #151 each carried their own copy
of the headless-Vim launcher. They now load helpers/vim, set up with
vim_fixture and start Vim with headless_vim, as every other file in
tests/vim does. No test changes what it checks.

Each file was seen to fail with one guarded behaviour broken: the Insert
mode StatusLine colour (colors), g:ale_disable_lsp in the early ale.vim
(ale-settings) and 'spellfile' (tidy).

Co-Authored-By: AI Agent <noreply@harleypig.com>

---------

Co-authored-by: AI Agent <noreply@harleypig.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: share the repo fixture in tests/shell and the Vim launcher in tests/vim

1 participant