Skip to content

Add BATS test suite for wt toolkit#12

Merged
guodong-sq merged 1 commit intomainfrom
guodong/add_bats_tests
Feb 9, 2026
Merged

Add BATS test suite for wt toolkit#12
guodong-sq merged 1 commit intomainfrom
guodong/add_bats_tests

Conversation

@guodong-sq
Copy link
Copy Markdown
Collaborator

@guodong-sq guodong-sq commented Feb 9, 2026

Summary

Initial attempt to add test coverage for the wt worktree toolkit using BATS (Bash Automated Testing System).

This PR adds 167 tests across three layers:

  • Unit tests (test/unit/) - Direct function-level tests for library code (wt-common, wt-context, wt-context-setup). Tests output helpers, git helpers, path expansion, metadata detection, context CRUD operations, and config loading.

  • Integration tests (test/integration/) - Per-command tests for each bin/wt-* script (wt-add, wt-cd, wt-context, wt-list, wt-metadata-export, wt-metadata-import, wt-remove, wt-switch). Each test creates isolated git repos in temp directories and validates real git operations, file system state, symlink behavior, error handling, and safety checks.

  • E2E tests (test/e2e/) - Full workflow tests covering complete worktree lifecycle (create, switch, work, remove), multi-worktree management, new branch creation with -b, context switching across repositories, dirty worktree handling, and symlink consistency across repeated operations.

Test infrastructure

  • BATS core, bats-assert, and bats-support added as git submodules under test/
  • Shared test helper (test/test_helper/common.bash) provides isolated HOME per test, mock git repo creation, context/worktree/branch creation helpers, and custom assertions

Source fixes discovered during testing

  • bin/wt-list: Added usage() function and -h/--help flag; switched to pwd -P for consistent path comparison with git worktree list output
  • lib/wt-common: Refactored config loading to source wt-context library directly instead of custom line-by-line parsing; switched wt_get_linked_worktree to use pwd -P for macOS symlink consistency
  • bin/wt-add: Improved install_bazel_symlinks_for_worktree documentation

Test plan

  • All 167 tests pass locally

Add comprehensive test coverage for all wt scripts using BATS
(Bash Automated Testing System) with bats-assert and bats-support
as git submodules.

Test structure:
- test/unit/        — library function tests (wt-common, wt-context, wt-context-setup)
- test/integration/ — per-command tests (wt-add, wt-cd, wt-context, wt-list,
                      wt-metadata-export, wt-metadata-import, wt-remove, wt-switch)
- test/e2e/         — full workflow tests (lifecycle, multi-worktree, context switching)
- test/test_helper/ — shared setup, teardown, and assertion helpers
- test/README.md    — test architecture docs and guide for adding new tests

Source fixes applied during test development:
- wt-list: add usage() function, -h/--help flag, use pwd -P for consistent
  path comparison with git worktree list output
- wt-common: refactor config loading to source wt-context library directly
  instead of custom parsing; use pwd -P in wt_get_linked_worktree for macOS
  symlink consistency (/var -> /private/var)
- wt-add: improve install_bazel_symlinks_for_worktree doc comment

Also update CONTRIBUTING.md to reference the new test suite.
@guodong-sq guodong-sq force-pushed the guodong/add_bats_tests branch from 3418b34 to 58ed518 Compare February 9, 2026 21:56
@guodong-sq guodong-sq merged commit 2580c8e into main Feb 9, 2026
1 check passed
@guodong-sq guodong-sq deleted the guodong/add_bats_tests branch March 10, 2026 06:25
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.

1 participant