summaryrefslogtreecommitdiff
path: root/tests/test-prog-shell--format-wiring.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-30 10:24:39 -0500
committerCraig Jennings <c@cjennings.net>2026-04-30 10:24:39 -0500
commitbb936fc082d4feb6a8759399ae07c840ea386b68 (patch)
treed40202ce3ccbef02998ae956a9925e11b6b0b64d /tests/test-prog-shell--format-wiring.el
parentd28bd8404f856985d82d493416633fee02e737f5 (diff)
downloaddotemacs-bb936fc082d4feb6a8759399ae07c840ea386b68.tar.gz
dotemacs-bb936fc082d4feb6a8759399ae07c840ea386b68.zip
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.
Diffstat (limited to 'tests/test-prog-shell--format-wiring.el')
-rw-r--r--tests/test-prog-shell--format-wiring.el58
1 files changed, 58 insertions, 0 deletions
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