summaryrefslogtreecommitdiff
path: root/tests
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
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')
-rw-r--r--tests/test-prog-go--format-wiring.el46
-rw-r--r--tests/test-prog-python--format-wiring.el40
-rw-r--r--tests/test-prog-shell--format-wiring.el58
-rw-r--r--tests/test-prog-webdev--format-wiring.el44
-rw-r--r--tests/testutil-format-wiring.el38
5 files changed, 226 insertions, 0 deletions
diff --git a/tests/test-prog-go--format-wiring.el b/tests/test-prog-go--format-wiring.el
new file mode 100644
index 00000000..99d80772
--- /dev/null
+++ b/tests/test-prog-go--format-wiring.el
@@ -0,0 +1,46 @@
+;;; test-prog-go--format-wiring.el --- Verify the Go formatter is wired -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Go's binding is installed via `local-set-key' inside the
+;; `cj/go-mode-keybindings' hook, not via use-package's `:bind'. The
+;; test runs the hook directly in a temp buffer and asks the buffer-
+;; local map what C-; f resolves to.
+;;
+;; Three checks:
+;; 1. `gofmt' is fboundp after go-mode loads.
+;; 2. The hook installs C-; f → `gofmt' in the buffer-local map.
+;; 3. `gofmt' (or `goimports') is on PATH.
+
+;;; Code:
+
+(require 'ert)
+
+(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)
+(ignore-errors (require 'prog-go))
+(require 'go-mode)
+
+(ert-deftest test-prog-go-format-command-fboundp ()
+ "Normal: `gofmt' is fboundp after `go-mode' loads."
+ (should (fboundp 'gofmt)))
+
+(ert-deftest test-prog-go-format-binding-resolves ()
+ "Normal: `cj/go-mode-keybindings' installs C-; f → `gofmt' locally."
+ (with-temp-buffer
+ (cj/go-mode-keybindings)
+ (should (eq 'gofmt (local-key-binding (kbd "C-; f"))))))
+
+(ert-deftest test-prog-go-format-executable-on-path ()
+ "Boundary: `gofmt' or `goimports' is on PATH (skipped if neither installed).
+The Go config sets `gofmt-command' to \"goimports\" but falls back to
+plain `gofmt' if goimports isn't installed."
+ (unless (or (executable-find "gofmt") (executable-find "goimports"))
+ (ert-skip "Neither gofmt nor goimports on PATH"))
+ (should (or (executable-find "gofmt")
+ (executable-find "goimports"))))
+
+(provide 'test-prog-go--format-wiring)
+;;; test-prog-go--format-wiring.el ends here
diff --git a/tests/test-prog-python--format-wiring.el b/tests/test-prog-python--format-wiring.el
new file mode 100644
index 00000000..67c18dd1
--- /dev/null
+++ b/tests/test-prog-python--format-wiring.el
@@ -0,0 +1,40 @@
+;;; test-prog-python--format-wiring.el --- Verify the Python formatter is wired -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Three checks for the Python formatter:
+;; 1. `blacken-buffer' is fboundp after the prog-python config loads.
+;; 2. C-; f in `python-ts-mode-map' resolves to `blacken-buffer'.
+;; 3. The `black' executable is on PATH (skipped if not installed).
+
+;;; Code:
+
+(require 'ert)
+
+(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)
+;; use-package's `:bind (:map ...)' defers until the named map exists.
+;; Loading python.el populates `python-ts-mode-map'; loading blacken
+;; resolves the binding form's late-binding hook.
+(ignore-errors (require 'prog-python))
+(require 'python)
+(require 'blacken)
+
+(ert-deftest test-prog-python-format-command-fboundp ()
+ "Normal: `blacken-buffer' is fboundp after the package is loaded."
+ (should (fboundp 'blacken-buffer)))
+
+(ert-deftest test-prog-python-format-binding-resolves ()
+ "Normal: C-; f in `python-ts-mode-map' is bound to `blacken-buffer'."
+ (should (eq 'blacken-buffer
+ (lookup-key python-ts-mode-map (kbd "C-; f")))))
+
+(ert-deftest test-prog-python-format-executable-on-path ()
+ "Boundary: the `black' executable is on PATH (skipped if not installed)."
+ (format-test--skip-unless-executable "black")
+ (should (executable-find "black")))
+
+(provide 'test-prog-python--format-wiring)
+;;; test-prog-python--format-wiring.el ends here
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
diff --git a/tests/test-prog-webdev--format-wiring.el b/tests/test-prog-webdev--format-wiring.el
new file mode 100644
index 00000000..7d9914f2
--- /dev/null
+++ b/tests/test-prog-webdev--format-wiring.el
@@ -0,0 +1,44 @@
+;;; test-prog-webdev--format-wiring.el --- Verify the TS/JS formatter is wired -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Webdev's binding is installed via `local-set-key' inside the
+;; `cj/webdev-keybindings' hook, fired from typescript-ts-mode,
+;; tsx-ts-mode, js-ts-mode, and web-mode. The format command itself
+;; (`cj/webdev-format-buffer') is defined in prog-webdev.el and shells
+;; out to the `prettier' binary.
+;;
+;; Three checks:
+;; 1. `cj/webdev-format-buffer' is fboundp.
+;; 2. The hook installs C-; f → `cj/webdev-format-buffer' in the
+;; buffer-local map.
+;; 3. The `prettier' executable is on PATH.
+
+;;; Code:
+
+(require 'ert)
+
+(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)
+(ignore-errors (require 'prog-webdev))
+
+(ert-deftest test-prog-webdev-format-command-fboundp ()
+ "Normal: `cj/webdev-format-buffer' is fboundp from prog-webdev."
+ (should (fboundp 'cj/webdev-format-buffer)))
+
+(ert-deftest test-prog-webdev-format-binding-resolves ()
+ "Normal: `cj/webdev-keybindings' installs C-; f → `cj/webdev-format-buffer'."
+ (with-temp-buffer
+ (cj/webdev-keybindings)
+ (should (eq 'cj/webdev-format-buffer
+ (local-key-binding (kbd "C-; f"))))))
+
+(ert-deftest test-prog-webdev-format-executable-on-path ()
+ "Boundary: `prettier' is on PATH (skipped if not installed)."
+ (format-test--skip-unless-executable "prettier")
+ (should (executable-find "prettier")))
+
+(provide 'test-prog-webdev--format-wiring)
+;;; test-prog-webdev--format-wiring.el ends here
diff --git a/tests/testutil-format-wiring.el b/tests/testutil-format-wiring.el
new file mode 100644
index 00000000..eba57564
--- /dev/null
+++ b/tests/testutil-format-wiring.el
@@ -0,0 +1,38 @@
+;;; testutil-format-wiring.el --- Shared helpers for formatter wiring tests -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Helpers used by the per-language formatter-wiring tests. Two pieces:
+;;
+;; - `format-test--ensure-packages-init' bootstraps `package' once per
+;; batch run so use-package forms in the prog-* modules can find
+;; their packages in elpa. The Makefile's test target invokes Emacs
+;; with --no-site-file --no-site-lisp, which skips the implicit
+;; `package-initialize' that an interactive session would do at
+;; startup.
+;;
+;; - `format-test--skip-unless-executable' is a thin wrapper around
+;; `ert-skip' for the "formatter not installed on this machine" path.
+;; Tests that need the underlying binary on PATH call this first.
+
+;;; Code:
+
+(require 'ert)
+(require 'package)
+
+(defvar format-test--packages-initialized nil
+ "Non-nil once `package-initialize' has run in this batch process.")
+
+(defun format-test--ensure-packages-init ()
+ "Initialise `package' the first time this is called in a batch run."
+ (unless format-test--packages-initialized
+ (package-initialize)
+ (setq format-test--packages-initialized t)))
+
+(defun format-test--skip-unless-executable (program)
+ "Skip the current ERT test unless PROGRAM is on PATH."
+ (unless (executable-find program)
+ (ert-skip (format "%s not on PATH; skipping installation-dependent assertion"
+ program))))
+
+(provide 'testutil-format-wiring)
+;;; testutil-format-wiring.el ends here