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-python--format-wiring.el | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test-prog-python--format-wiring.el (limited to 'tests/test-prog-python--format-wiring.el') 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 -- cgit v1.2.3