aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-18 17:45:00 -0500
committerCraig Jennings <c@cjennings.net>2026-07-18 17:45:00 -0500
commit3f734920d2713924124b3fe8b0edf0c4b9c82bc8 (patch)
treef4f65074418bddf71717fdbea9cd6069669fa888 /tests
parent347e36c6fd4b52e14731594e6f745f6efdccadb1 (diff)
downloaddotemacs-3f734920d2713924124b3fe8b0edf0c4b9c82bc8.tar.gz
dotemacs-3f734920d2713924124b3fe8b0edf0c4b9c82bc8.zip
fix(prog): cover classic modes and warn for missing dev tools
Classic go-mode and js-mode buffers got none of the ts-mode setup, and web-mode got the format key without the promised company/flyspell/LSP. All three now run the shared setup. The web-mode LSP attach guards on the HTML language server, so machines without it stay silent instead of prompting. gopls, clangd, clang-format, bash-language-server, shfmt, and shellcheck now warn at load when missing. The shfmt, shellcheck, and clang-format blocks gate on :if, which evaluates once at startup, so an absent tool silently disabled that setup until the next restart. I also put ~/go/bin on exec-path at load so the gopls check doesn't misreport a gopls installed there.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-prog-c--tool-warnings.el34
-rw-r--r--tests/test-prog-go--classic-mode-hooks.el46
-rw-r--r--tests/test-prog-shell--tool-warnings.el34
-rw-r--r--tests/test-prog-webdev--classic-and-web-mode-hooks.el78
4 files changed, 192 insertions, 0 deletions
diff --git a/tests/test-prog-c--tool-warnings.el b/tests/test-prog-c--tool-warnings.el
new file mode 100644
index 00000000..9d4da57e
--- /dev/null
+++ b/tests/test-prog-c--tool-warnings.el
@@ -0,0 +1,34 @@
+;;; test-prog-c--tool-warnings.el --- Load-time missing-tool warnings -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; The config audit flagged clangd for the load-time missing-tool
+;; warning pyright/prettier already have. clang-format is the same
+;; class: its use-package block gates on `:if (executable-find ...)',
+;; which evaluates once at startup, so an absent binary silently
+;; disables the format key until the next restart — the warn is the
+;; only visible trace.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(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)
+(require 'prog-c)
+
+(ert-deftest test-prog-c-warns-when-tools-missing ()
+ "Error: loading without the C tools on PATH warns for each one."
+ (let ((warned '()))
+ (cl-letf (((symbol-function 'executable-find) (lambda (&rest _) nil))
+ ((symbol-function 'display-warning)
+ (lambda (_type msg &rest _) (push msg warned))))
+ (load (expand-file-name "modules/prog-c.el" user-emacs-directory) nil t))
+ (dolist (tool '("clangd" "clang-format"))
+ (should (cl-some (lambda (m) (string-match-p (regexp-quote tool) m))
+ warned)))))
+
+(provide 'test-prog-c--tool-warnings)
+;;; test-prog-c--tool-warnings.el ends here
diff --git a/tests/test-prog-go--classic-mode-hooks.el b/tests/test-prog-go--classic-mode-hooks.el
new file mode 100644
index 00000000..a9defe2e
--- /dev/null
+++ b/tests/test-prog-go--classic-mode-hooks.el
@@ -0,0 +1,46 @@
+;;; test-prog-go--classic-mode-hooks.el --- Classic go-mode hooks + gopls warn -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; The config audit found the Go setup hooks attached to go-ts-mode
+;; only, so a fallback to classic go-mode silently lost indent, keys,
+;; and LSP. It also flagged gopls for the load-time missing-tool
+;; warning pyright/prettier already have; that warn is only honest if
+;; ~/go/bin is on `exec-path' at load time (it used to join only in
+;; go-mode's deferred :config, so gopls installed there read as
+;; missing).
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(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)
+(require 'prog-go)
+
+(ert-deftest test-prog-go-hooks-cover-classic-go-mode ()
+ "Normal: classic go-mode runs the same setup + keybindings as go-ts-mode."
+ (dolist (hook '(go-mode-hook go-ts-mode-hook))
+ (should (memq #'cj/go-setup (symbol-value hook)))
+ (should (memq #'cj/go-mode-keybindings (symbol-value hook)))))
+
+(ert-deftest test-prog-go-bin-path-on-exec-path-at-load ()
+ "Normal: ~/go/bin joins `exec-path' at module load, not first go buffer.
+The load-time gopls warn resolves through `exec-path'; registering the
+Go bin directory only in go-mode's deferred :config would make gopls
+installed there warn as missing on every start."
+ (should (member go-bin-path exec-path)))
+
+(ert-deftest test-prog-go-warns-when-gopls-missing ()
+ "Error: loading the module without gopls on PATH warns about gopls."
+ (let ((warned '()))
+ (cl-letf (((symbol-function 'executable-find) (lambda (&rest _) nil))
+ ((symbol-function 'display-warning)
+ (lambda (_type msg &rest _) (push msg warned))))
+ (load (expand-file-name "modules/prog-go.el" user-emacs-directory) nil t))
+ (should (cl-some (lambda (m) (string-match-p "gopls" m)) warned))))
+
+(provide 'test-prog-go--classic-mode-hooks)
+;;; test-prog-go--classic-mode-hooks.el ends here
diff --git a/tests/test-prog-shell--tool-warnings.el b/tests/test-prog-shell--tool-warnings.el
new file mode 100644
index 00000000..37c1e559
--- /dev/null
+++ b/tests/test-prog-shell--tool-warnings.el
@@ -0,0 +1,34 @@
+;;; test-prog-shell--tool-warnings.el --- Load-time missing-tool warnings -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; The config audit flagged bash-language-server, shfmt, and shellcheck
+;; for the load-time missing-tool warnings pyright/prettier already
+;; have. The shfmt and flycheck use-package blocks gate on `:if
+;; (executable-find ...)', which evaluates once at startup — an absent
+;; tool silently disables that setup until the next restart, so the
+;; warn is the only visible trace.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(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)
+(require 'prog-shell)
+
+(ert-deftest test-prog-shell-warns-when-tools-missing ()
+ "Error: loading without the shell tools on PATH warns for each one."
+ (let ((warned '()))
+ (cl-letf (((symbol-function 'executable-find) (lambda (&rest _) nil))
+ ((symbol-function 'display-warning)
+ (lambda (_type msg &rest _) (push msg warned))))
+ (load (expand-file-name "modules/prog-shell.el" user-emacs-directory) nil t))
+ (dolist (tool '("bash-language-server" "shfmt" "shellcheck"))
+ (should (cl-some (lambda (m) (string-match-p (regexp-quote tool) m))
+ warned)))))
+
+(provide 'test-prog-shell--tool-warnings)
+;;; test-prog-shell--tool-warnings.el ends here
diff --git a/tests/test-prog-webdev--classic-and-web-mode-hooks.el b/tests/test-prog-webdev--classic-and-web-mode-hooks.el
new file mode 100644
index 00000000..20fc2fb8
--- /dev/null
+++ b/tests/test-prog-webdev--classic-and-web-mode-hooks.el
@@ -0,0 +1,78 @@
+;;; test-prog-webdev--classic-and-web-mode-hooks.el --- Classic js + web-mode setup hooks -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; The config audit found the webdev setup hooks attached to the
+;; tree-sitter modes only, so a grammar-unavailable fallback to classic
+;; js-mode silently lost indent/keys/LSP, and web-mode got the format
+;; key but none of the promised setup (no company/flyspell/LSP in HTML
+;; buffers). These tests pin the classic js-mode hooks and the
+;; web-mode setup hook, plus the html-language-server guard that keeps
+;; LSP silent on machines without the server.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(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)
+(require 'prog-webdev)
+
+(ert-deftest test-prog-webdev-hooks-cover-classic-js-mode ()
+ "Normal: classic js-mode runs the same setup + keybindings as js-ts-mode."
+ (should (memq #'cj/webdev-setup js-mode-hook))
+ (should (memq #'cj/webdev-keybindings js-mode-hook)))
+
+(ert-deftest test-prog-webdev-web-mode-hook-runs-setup ()
+ "Normal: web-mode runs `cj/web-mode-setup' alongside the keybindings."
+ (should (memq #'cj/web-mode-setup web-mode-hook))
+ (should (memq #'cj/webdev-keybindings web-mode-hook)))
+
+(ert-deftest test-prog-webdev-web-mode-setup-sets-buffer-local-preferences ()
+ "Normal: web-mode setup lands the shared webdev buffer preferences."
+ (with-temp-buffer
+ (cl-letf (((symbol-function 'company-mode) #'ignore)
+ ((symbol-function 'flyspell-prog-mode) #'ignore)
+ ((symbol-function 'superword-mode) #'ignore)
+ ((symbol-function 'electric-pair-local-mode) #'ignore)
+ ((symbol-function 'executable-find) (lambda (_ &rest _) nil)))
+ (cj/web-mode-setup))
+ (should (= fill-column 100))
+ (should (= tab-width 2))
+ (should-not indent-tabs-mode)))
+
+(ert-deftest test-prog-webdev-web-mode-setup-starts-lsp-when-html-server-on-path ()
+ "Normal: with the html language server on PATH, `lsp-deferred' fires."
+ (with-temp-buffer
+ (let ((started nil))
+ (cl-letf (((symbol-function 'company-mode) #'ignore)
+ ((symbol-function 'flyspell-prog-mode) #'ignore)
+ ((symbol-function 'superword-mode) #'ignore)
+ ((symbol-function 'electric-pair-local-mode) #'ignore)
+ ((symbol-function 'lsp-deferred)
+ (lambda (&rest _) (setq started t)))
+ ((symbol-function 'executable-find)
+ (lambda (path &rest _)
+ (when (equal path html-language-server-path)
+ "/usr/bin/vscode-html-language-server"))))
+ (cj/web-mode-setup))
+ (should started))))
+
+(ert-deftest test-prog-webdev-web-mode-setup-skips-lsp-without-html-server ()
+ "Boundary: without the html language server, `lsp-deferred' is NOT called."
+ (with-temp-buffer
+ (let ((started nil))
+ (cl-letf (((symbol-function 'company-mode) #'ignore)
+ ((symbol-function 'flyspell-prog-mode) #'ignore)
+ ((symbol-function 'superword-mode) #'ignore)
+ ((symbol-function 'electric-pair-local-mode) #'ignore)
+ ((symbol-function 'lsp-deferred)
+ (lambda (&rest _) (setq started t)))
+ ((symbol-function 'executable-find) (lambda (_ &rest _) nil)))
+ (cj/web-mode-setup))
+ (should-not started))))
+
+(provide 'test-prog-webdev--classic-and-web-mode-hooks)
+;;; test-prog-webdev--classic-and-web-mode-hooks.el ends here