aboutsummaryrefslogtreecommitdiff
path: root/tests/test-dev-fkeys--f4-derive-clean-cmd.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-03 16:13:21 -0500
committerCraig Jennings <c@cjennings.net>2026-05-03 16:13:21 -0500
commit2c94acd52cc92dc4ebefd999dbca771367cc3090 (patch)
tree2c9ed2df067e736c98c0b7fa36ed3655d8b85e16 /tests/test-dev-fkeys--f4-derive-clean-cmd.el
parent8ec668d6749b22f47a4c614d0965445dcfa86f50 (diff)
downloaddotemacs-2c94acd52cc92dc4ebefd999dbca771367cc3090.tar.gz
dotemacs-2c94acd52cc92dc4ebefd999dbca771367cc3090.zip
feat(dev-fkeys): add project-aware F4 compile/run dispatcher
I added a new module `modules/dev-fkeys.el` that owns the dev F-key block. F4 prompts via `completing-read` with a candidate set filtered by project type (compiled / interpreted / unknown). C-F4 is the compile-only fast path. M-F4 is clean + rebuild. It runs a heuristic clean command derived from the project markers (go.mod, Cargo.toml, Eask, Makefile, CMakeLists.txt) and chains `projectile-compile-project` on success. S-F4 stays on `recompile` and now lives globally instead of duplicated across prog-general.el and prog-c.el. F6 is bound globally to `projectile-test-project` as a Phase 1 stopgap. Phase 2 replaces it with the polyglot test runner spec'd in todo.org. Project-type detection runs against the projectile root and falls back to `unknown` when no marker matches. Interpreted markers are checked first so a Python or Node project with a Makefile for tasks classifies as interpreted instead of compiled. Compile + Run sequencing uses a one-shot `compilation-finish-functions` hook that self-removes on first invocation and only fires the follow-up when the status string starts with `finished`. Cleanup in the same commit: - Dropped F4/F5/F6 from `prog-general.el`'s prog-mode-hook. They are now global. - Dropped F6→format bindings from prog-c.el / prog-python.el / prog-shell.el. C-; f was already bound in each, so this is pure removal. - Dropped the duplicate S-F4 from prog-c.el. The global binding covers it. - Updated the keybinding header in prog-general.el and the workflow comments in prog-c.el / prog-shell.el. - Wired `(require 'dev-fkeys)` in init.el alongside coverage-core. TDD: 73 tests across 11 files, one per helper. Production code is split into small testable internals (`cj/--detect-project-type`, `cj/--f4-candidates`, `cj/--f4-derive-clean-cmd`, `cj/--f4-make-once-hook`, `cj/--f4-dispatch`, `cj/--f4-compile-and-run-impl`, `cj/--f4-clean-rebuild-impl`, `cj/--f4-project-root`) plus three thin interactive wrappers. Smoke tests confirm bindings register on load. Known limitation: if another `compilation-finish-functions` hook fires between my add-hook and the compile finishing, the chain can fire on the wrong compile. The hook self-removes on first invocation regardless of which compile it sees. Documented in the impl docstring. Acceptable for v1. Phase 2 will replace F6 with the polyglot test runner (tree-sitter queries for Python/Go/TS, sexp scan for Elisp, buffer-local last-test memory).
Diffstat (limited to 'tests/test-dev-fkeys--f4-derive-clean-cmd.el')
-rw-r--r--tests/test-dev-fkeys--f4-derive-clean-cmd.el93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/test-dev-fkeys--f4-derive-clean-cmd.el b/tests/test-dev-fkeys--f4-derive-clean-cmd.el
new file mode 100644
index 00000000..9052bf55
--- /dev/null
+++ b/tests/test-dev-fkeys--f4-derive-clean-cmd.el
@@ -0,0 +1,93 @@
+;;; test-dev-fkeys--f4-derive-clean-cmd.el --- Tests for cj/--f4-derive-clean-cmd -*- lexical-binding: t -*-
+
+;;; Commentary:
+;; Tests for the heuristic clean-command picker used by M-F4
+;; (Clean + Rebuild). Returns a shell command string based on the project
+;; root's marker files, or nil when no marker matches.
+
+;;; Code:
+
+(require 'ert)
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'dev-fkeys)
+
+(defmacro test-dev-fkeys-clean--with-project-dir (markers &rest body)
+ "Create a temp project dir with each filename in MARKERS as an empty file.
+Bind the dir path to ROOT in BODY. Cleans up on exit."
+ (declare (indent 1))
+ `(let ((root (make-temp-file "test-dev-fkeys-clean-" t)))
+ (unwind-protect
+ (progn
+ (dolist (marker ,markers)
+ (write-region "" nil (expand-file-name marker root)))
+ ,@body)
+ (delete-directory root t))))
+
+;;; Normal Cases
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-go-mod-uses-go-clean ()
+ "Normal: go.mod yields go clean ./..."
+ (test-dev-fkeys-clean--with-project-dir '("go.mod")
+ (should (string= (cj/--f4-derive-clean-cmd root) "go clean ./..."))))
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-cargo-toml-uses-cargo-clean ()
+ "Normal: Cargo.toml yields cargo clean."
+ (test-dev-fkeys-clean--with-project-dir '("Cargo.toml")
+ (should (string= (cj/--f4-derive-clean-cmd root) "cargo clean"))))
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-eask-uses-eask-clean ()
+ "Normal: Eask yields eask clean."
+ (test-dev-fkeys-clean--with-project-dir '("Eask")
+ (should (string= (cj/--f4-derive-clean-cmd root) "eask clean"))))
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-makefile-uses-make-clean ()
+ "Normal: Makefile yields make clean."
+ (test-dev-fkeys-clean--with-project-dir '("Makefile")
+ (should (string= (cj/--f4-derive-clean-cmd root) "make clean"))))
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-cmakelists-uses-cmake-clean ()
+ "Normal: CMakeLists.txt yields cmake build-dir clean target."
+ (test-dev-fkeys-clean--with-project-dir '("CMakeLists.txt")
+ (should (string= (cj/--f4-derive-clean-cmd root)
+ "cmake --build build --target clean"))))
+
+;;; Boundary Cases
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-go-wins-over-makefile ()
+ "Boundary: go.mod + Makefile picks go clean (go.mod is checked first)."
+ (test-dev-fkeys-clean--with-project-dir '("go.mod" "Makefile")
+ (should (string= (cj/--f4-derive-clean-cmd root) "go clean ./..."))))
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-cargo-wins-over-makefile ()
+ "Boundary: Cargo.toml + Makefile picks cargo clean."
+ (test-dev-fkeys-clean--with-project-dir '("Cargo.toml" "Makefile")
+ (should (string= (cj/--f4-derive-clean-cmd root) "cargo clean"))))
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-eask-wins-over-makefile ()
+ "Boundary: Eask + Makefile picks eask clean."
+ (test-dev-fkeys-clean--with-project-dir '("Eask" "Makefile")
+ (should (string= (cj/--f4-derive-clean-cmd root) "eask clean"))))
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-no-markers-returns-nil ()
+ "Boundary: directory with no recognized markers returns nil."
+ (test-dev-fkeys-clean--with-project-dir '()
+ (should (null (cj/--f4-derive-clean-cmd root)))))
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-irrelevant-files-returns-nil ()
+ "Boundary: only unrelated files returns nil."
+ (test-dev-fkeys-clean--with-project-dir '("README.md" "LICENSE")
+ (should (null (cj/--f4-derive-clean-cmd root)))))
+
+;;; Error Cases
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-nil-root-returns-nil ()
+ "Error: nil ROOT returns nil with no error."
+ (should (null (cj/--f4-derive-clean-cmd nil))))
+
+(ert-deftest test-dev-fkeys-derive-clean-cmd-nonexistent-root-returns-nil ()
+ "Error: a non-existent path returns nil. file-exists-p returns nil so no
+marker matches."
+ (should (null (cj/--f4-derive-clean-cmd "/nonexistent/path/xyzzy"))))
+
+(provide 'test-dev-fkeys--f4-derive-clean-cmd)
+;;; test-dev-fkeys--f4-derive-clean-cmd.el ends here