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