summaryrefslogtreecommitdiff
path: root/tests/test-prog-c-mode-settings.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-03 20:08:35 -0500
committerCraig Jennings <c@cjennings.net>2026-05-03 20:08:35 -0500
commitf619cbf9f384dfd6976e3bed448b3473146841e1 (patch)
tree3a11e1b4ab89c0e35d5c1f12141bd09f731b3fc8 /tests/test-prog-c-mode-settings.el
parentdeff663d480afb23e47f0d0fd834d2c0959d0b00 (diff)
downloaddotemacs-f619cbf9f384dfd6976e3bed448b3473146841e1.tar.gz
dotemacs-f619cbf9f384dfd6976e3bed448b3473146841e1.zip
test: cover C mode hooks and project compile branches
I added 7 new tests across 3 files, filling coverage gaps in `prog-c.el`. Two functions were untested (`cj/c-mode-settings`, `cj/c-mode-keybindings`) and `cj/c-compile-command` only had its single-file fallback covered. `cj/c-compile-command` now has the Makefile and CMake branches tested, plus a Boundary case for a Makefile path with spaces being shell-quoted in the `cd` target. I added these to the existing `test-prog-c-compile-command.el` since the helper and dispatcher already lived there. `cj/c-mode-settings` gets three tests. One covers the buffer-local invariants (`indent-tabs-mode` nil, `c-basic-offset` 4, `tab-width` 4, `fill-column` 80, `comment-auto-fill-only-comments` t). The other two cover the LSP branch: `lsp-deferred` runs when the function is fbound and `executable-find` returns a clangd path, and skips when clangd is missing. `cj/c-mode-keybindings` gets one test asserting S-F5 binds to `cj/disabled` and S-F6 binds to `gdb` in the buffer's local keymap. No realistic Boundary or Error cases for installing two static bindings, so the single Normal case carries it. I stubbed `auto-fill-mode`, `electric-pair-mode`, `lsp-deferred`, `executable-find`, and `locate-dominating-file` at the boundaries via `cl-letf`. Buffer-local state was exercised real in `with-temp-buffer`. 12 prog-c tests pass together: 5 existing plus 7 new.
Diffstat (limited to 'tests/test-prog-c-mode-settings.el')
-rw-r--r--tests/test-prog-c-mode-settings.el52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test-prog-c-mode-settings.el b/tests/test-prog-c-mode-settings.el
new file mode 100644
index 00000000..eef2d910
--- /dev/null
+++ b/tests/test-prog-c-mode-settings.el
@@ -0,0 +1,52 @@
+;;; test-prog-c-mode-settings.el --- Tests for cj/c-mode-settings -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Verifies the C mode hook applies the documented buffer-local values and
+;; only calls `lsp-deferred' when both the function and clangd are available.
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'ert)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'prog-c)
+
+(ert-deftest test-prog-c-mode-settings-normal-applies-buffer-locals ()
+ "Normal: cj/c-mode-settings applies the documented buffer-local values."
+ (with-temp-buffer
+ (cl-letf (((symbol-function 'auto-fill-mode) (lambda (&rest _) nil))
+ ((symbol-function 'electric-pair-mode) (lambda (&rest _) nil))
+ ((symbol-function 'lsp-deferred) (lambda (&rest _) nil))
+ ((symbol-function 'executable-find) (lambda (_) nil)))
+ (cj/c-mode-settings))
+ (should (eq indent-tabs-mode nil))
+ (should (= c-basic-offset 4))
+ (should (= tab-width 4))
+ (should (= fill-column 80))
+ (should comment-auto-fill-only-comments)))
+
+(ert-deftest test-prog-c-mode-settings-boundary-lsp-available-deferred ()
+ "Boundary: when lsp-deferred is fbound and clangd is on PATH, lsp-deferred is called."
+ (let ((lsp-calls 0))
+ (with-temp-buffer
+ (cl-letf (((symbol-function 'auto-fill-mode) (lambda (&rest _) nil))
+ ((symbol-function 'electric-pair-mode) (lambda (&rest _) nil))
+ ((symbol-function 'lsp-deferred) (lambda () (cl-incf lsp-calls)))
+ ((symbol-function 'executable-find) (lambda (_) "/usr/bin/clangd")))
+ (cj/c-mode-settings)))
+ (should (= lsp-calls 1))))
+
+(ert-deftest test-prog-c-mode-settings-error-clangd-missing-skips-lsp ()
+ "Error: when clangd is not on PATH, lsp-deferred is NOT called."
+ (let ((lsp-calls 0))
+ (with-temp-buffer
+ (cl-letf (((symbol-function 'auto-fill-mode) (lambda (&rest _) nil))
+ ((symbol-function 'electric-pair-mode) (lambda (&rest _) nil))
+ ((symbol-function 'lsp-deferred) (lambda () (cl-incf lsp-calls)))
+ ((symbol-function 'executable-find) (lambda (_) nil)))
+ (cj/c-mode-settings)))
+ (should (zerop lsp-calls))))
+
+(provide 'test-prog-c-mode-settings)
+;;; test-prog-c-mode-settings.el ends here