From f619cbf9f384dfd6976e3bed448b3473146841e1 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 3 May 2026 20:08:35 -0500 Subject: 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. --- tests/test-prog-c-mode-keybindings.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test-prog-c-mode-keybindings.el (limited to 'tests/test-prog-c-mode-keybindings.el') diff --git a/tests/test-prog-c-mode-keybindings.el b/tests/test-prog-c-mode-keybindings.el new file mode 100644 index 00000000..85b872b0 --- /dev/null +++ b/tests/test-prog-c-mode-keybindings.el @@ -0,0 +1,25 @@ +;;; test-prog-c-mode-keybindings.el --- Tests for cj/c-mode-keybindings -*- lexical-binding: t; -*- + +;;; Commentary: +;; Verifies the C mode hook installs the S-modifier overrides on the +;; current buffer's local keymap. + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'prog-c) + +(ert-deftest test-prog-c-mode-keybindings-normal-installs-fkey-overrides () + "Normal: cj/c-mode-keybindings binds S-F5 to cj/disabled and S-F6 to gdb." + (with-temp-buffer + (use-local-map (make-sparse-keymap)) + (cj/c-mode-keybindings) + (should (eq (lookup-key (current-local-map) (kbd "S-")) + 'cj/disabled)) + (should (eq (lookup-key (current-local-map) (kbd "S-")) + 'gdb)))) + +(provide 'test-prog-c-mode-keybindings) +;;; test-prog-c-mode-keybindings.el ends here -- cgit v1.2.3