From bb936fc082d4feb6a8759399ae07c840ea386b68 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 30 Apr 2026 10:24:39 -0500 Subject: test(prog): cover formatter wiring for python, go, shell, typescript Four test files plus a shared testutil that locks in the formatter bindings on C-; f across the four languages. Each test file checks: - the format command is fboundp after the relevant package loads - the C-; f binding resolves to that command (in the relevant mode-map, or in the buffer-local map for hook-based wiring) - the underlying executable is on PATH (skipped via ert-skip if not installed) No production change. The bindings were already at C-; f via two mechanisms. Use-package :bind handles python and shell. The other two install via local-set-key inside a hook. This regression net catches silent breakage if any of those wirings get reshaped later. The shared tests/testutil-format-wiring.el carries format-test--ensure-packages-init, which calls package-initialize once per batch run, since make test runs Emacs with --no-site-file --no-site-lisp. Without it, use-package can't find blacken / shfmt / go-mode in elpa/. Also format-test--skip-unless-executable wraps ert-skip with a clear "not on PATH" message so missing tools fail informatively. Per-language wiring inventory (no changes, just locked in): - Python: blacken-buffer in python-ts-mode-map (use-package :bind) - Shell: shfmt-buffer in sh-mode-map and bash-ts-mode-map (use-package :bind, gated on :if executable-find) - Go: gofmt via cj/go-mode-keybindings hook - TS/JS/Web: cj/webdev-format-buffer via cj/webdev-keybindings hook 13 tests across 4 files, all passing. --- tests/test-prog-shell--format-wiring.el | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/test-prog-shell--format-wiring.el (limited to 'tests/test-prog-shell--format-wiring.el') diff --git a/tests/test-prog-shell--format-wiring.el b/tests/test-prog-shell--format-wiring.el new file mode 100644 index 00000000..4a014943 --- /dev/null +++ b/tests/test-prog-shell--format-wiring.el @@ -0,0 +1,58 @@ +;;; test-prog-shell--format-wiring.el --- Verify the Shell formatter is wired -*- lexical-binding: t; -*- + +;;; Commentary: +;; The shfmt use-package gates on `:if (executable-find shfmt-path)' so +;; the keymap entries only install when shfmt is on PATH. The bind/ +;; fboundp tests therefore call the executable-skip helper first. +;; +;; Three checks for the shell formatter, each repeated for the two +;; relevant mode-maps (`sh-mode-map' and `bash-ts-mode-map'): +;; 1. `shfmt-buffer' is fboundp. +;; 2. C-; f in each map resolves to `shfmt-buffer'. +;; 3. The `shfmt' executable is on PATH. + +;;; Code: + +(require 'ert) +(require 'sh-script) ; provides sh-mode-map + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) +(require 'testutil-format-wiring) + +(format-test--ensure-packages-init) +;; bash-ts-mode is autoloaded from sh-script in modern Emacs; force +;; the map into existence by referencing the mode definition. When +;; tree-sitter isn't built in, bash-ts-mode is still defined as a +;; symbol via define-derived-mode, and its keymap exists. +(ignore-errors (require 'prog-shell)) +(when (executable-find "shfmt") + (require 'shfmt)) + +(ert-deftest test-prog-shell-format-command-fboundp () + "Normal: `shfmt-buffer' is fboundp after shfmt loads. +Skipped when shfmt isn't installed because the use-package gates on +`:if (executable-find shfmt-path)'." + (format-test--skip-unless-executable "shfmt") + (should (fboundp 'shfmt-buffer))) + +(ert-deftest test-prog-shell-format-binding-in-sh-mode () + "Normal: C-; f in `sh-mode-map' is bound to `shfmt-buffer'." + (format-test--skip-unless-executable "shfmt") + (should (eq 'shfmt-buffer + (lookup-key sh-mode-map (kbd "C-; f"))))) + +(ert-deftest test-prog-shell-format-binding-in-bash-ts-mode () + "Normal: C-; f in `bash-ts-mode-map' is bound to `shfmt-buffer'." + (format-test--skip-unless-executable "shfmt") + (should (boundp 'bash-ts-mode-map)) + (should (eq 'shfmt-buffer + (lookup-key bash-ts-mode-map (kbd "C-; f"))))) + +(ert-deftest test-prog-shell-format-executable-on-path () + "Boundary: the `shfmt' executable is on PATH (skipped if not installed)." + (format-test--skip-unless-executable "shfmt") + (should (executable-find "shfmt"))) + +(provide 'test-prog-shell--format-wiring) +;;; test-prog-shell--format-wiring.el ends here -- cgit v1.2.3