diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-03 16:13:21 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-03 16:13:21 -0500 |
| commit | 2c94acd52cc92dc4ebefd999dbca771367cc3090 (patch) | |
| tree | 2c9ed2df067e736c98c0b7fa36ed3655d8b85e16 /tests | |
| parent | 8ec668d6749b22f47a4c614d0965445dcfa86f50 (diff) | |
| download | dotemacs-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')
| -rw-r--r-- | tests/test-dev-fkeys--detect-project-type.el | 117 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-candidates.el | 66 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-clean-rebuild-impl.el | 118 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-clean-rebuild.el | 61 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-compile-and-run-impl.el | 75 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-compile-and-run.el | 94 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-compile-only.el | 61 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-derive-clean-cmd.el | 93 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-dispatch.el | 78 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-make-once-hook.el | 115 | ||||
| -rw-r--r-- | tests/test-dev-fkeys--f4-project-root.el | 51 |
11 files changed, 929 insertions, 0 deletions
diff --git a/tests/test-dev-fkeys--detect-project-type.el b/tests/test-dev-fkeys--detect-project-type.el new file mode 100644 index 00000000..3b306484 --- /dev/null +++ b/tests/test-dev-fkeys--detect-project-type.el @@ -0,0 +1,117 @@ +;;; test-dev-fkeys--detect-project-type.el --- Tests for cj/--detect-project-type -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the project-type classifier in dev-fkeys.el. +;; The classifier returns 'compiled, 'interpreted, or 'unknown based on +;; marker files at the project root. Interpreted markers are checked first +;; so a Python or Node project with a Makefile for tasks classifies as +;; interpreted. + +;;; Code: + +(require 'ert) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +(defmacro test-dev-fkeys--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-" 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-detect-project-type-go-mod-is-compiled () + "Normal: go.mod marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("go.mod") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-cargo-toml-is-compiled () + "Normal: Cargo.toml marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("Cargo.toml") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-cmakelists-is-compiled () + "Normal: CMakeLists.txt marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("CMakeLists.txt") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-makefile-is-compiled () + "Normal: Makefile marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("Makefile") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-eask-is-compiled () + "Normal: Eask marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("Eask") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-pyproject-is-interpreted () + "Normal: pyproject.toml marker classifies as interpreted." + (test-dev-fkeys--with-project-dir '("pyproject.toml") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-requirements-is-interpreted () + "Normal: requirements.txt marker classifies as interpreted." + (test-dev-fkeys--with-project-dir '("requirements.txt") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-pipfile-is-interpreted () + "Normal: Pipfile marker classifies as interpreted." + (test-dev-fkeys--with-project-dir '("Pipfile") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-package-json-is-interpreted () + "Normal: package.json marker classifies as interpreted." + (test-dev-fkeys--with-project-dir '("package.json") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-detect-project-type-interpreted-wins-over-compiled () + "Boundary: a Python project with a Makefile classifies as interpreted. +Interpreted markers are checked first so task-runner Makefiles in +Python/Node projects don't misclassify them as compiled." + (test-dev-fkeys--with-project-dir '("pyproject.toml" "Makefile") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-package-json-wins-over-makefile () + "Boundary: package.json + Makefile classifies as interpreted." + (test-dev-fkeys--with-project-dir '("package.json" "Makefile") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-pure-c-with-makefile-is-compiled () + "Boundary: a Makefile alone (no interpreted markers) classifies as compiled. +This is the typical pure-C project case." + (test-dev-fkeys--with-project-dir '("Makefile") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-no-markers-is-unknown () + "Boundary: directory with no markers classifies as unknown." + (test-dev-fkeys--with-project-dir '() + (should (eq (cj/--detect-project-type root) 'unknown)))) + +(ert-deftest test-dev-fkeys-detect-project-type-irrelevant-file-is-unknown () + "Boundary: unrelated files in root don't trigger any classification." + (test-dev-fkeys--with-project-dir '("README.md" "LICENSE" ".gitignore") + (should (eq (cj/--detect-project-type root) 'unknown)))) + +;;; Error Cases + +(ert-deftest test-dev-fkeys-detect-project-type-nil-root-is-unknown () + "Error: nil ROOT returns 'unknown (buffer not in a project)." + (should (eq (cj/--detect-project-type nil) 'unknown))) + +(ert-deftest test-dev-fkeys-detect-project-type-nonexistent-root-is-unknown () + "Error: a directory path that doesn't exist returns 'unknown. +file-exists-p on a non-existent path returns nil, so no marker matches." + (should (eq (cj/--detect-project-type "/nonexistent/path/xyzzy") 'unknown))) + +(provide 'test-dev-fkeys--detect-project-type) +;;; test-dev-fkeys--detect-project-type.el ends here diff --git a/tests/test-dev-fkeys--f4-candidates.el b/tests/test-dev-fkeys--f4-candidates.el new file mode 100644 index 00000000..a2d1afa4 --- /dev/null +++ b/tests/test-dev-fkeys--f4-candidates.el @@ -0,0 +1,66 @@ +;;; test-dev-fkeys--f4-candidates.el --- Tests for cj/--f4-candidates -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the candidate-menu builder. Returns an alist of +;; (LABEL . ACTION) for the F4 completing-read prompt. The first entry +;; is the default (selected on RET). + +;;; Code: + +(require 'ert) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +;;; Normal Cases + +(ert-deftest test-dev-fkeys-f4-candidates-compiled-has-four-entries () + "Normal: compiled project gets all four candidates." + (let ((cands (cj/--f4-candidates 'compiled))) + (should (= (length cands) 4)))) + +(ert-deftest test-dev-fkeys-f4-candidates-compiled-default-is-compile-and-run () + "Normal: first candidate for compiled is Compile + Run (the default)." + (let ((cands (cj/--f4-candidates 'compiled))) + (should (equal (caar cands) "Compile + Run")) + (should (eq (cdar cands) 'compile-and-run)))) + +(ert-deftest test-dev-fkeys-f4-candidates-compiled-includes-all-actions () + "Normal: compiled menu maps each label to its action symbol." + (let ((cands (cj/--f4-candidates 'compiled))) + (should (eq (cdr (assoc "Compile + Run" cands)) 'compile-and-run)) + (should (eq (cdr (assoc "Compile" cands)) 'compile-only)) + (should (eq (cdr (assoc "Run" cands)) 'run-only)) + (should (eq (cdr (assoc "Clean + Rebuild" cands)) 'clean-rebuild)))) + +(ert-deftest test-dev-fkeys-f4-candidates-interpreted-is-run-only () + "Normal: interpreted project gets a single Run candidate." + (let ((cands (cj/--f4-candidates 'interpreted))) + (should (= (length cands) 1)) + (should (equal (caar cands) "Run")) + (should (eq (cdar cands) 'run-only)))) + +(ert-deftest test-dev-fkeys-f4-candidates-unknown-is-compile-plain () + "Normal: unknown project gets a single Compile candidate that calls plain compile." + (let ((cands (cj/--f4-candidates 'unknown))) + (should (= (length cands) 1)) + (should (equal (caar cands) "Compile")) + (should (eq (cdar cands) 'compile-plain)))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-f4-candidates-bogus-symbol-falls-back-to-unknown () + "Boundary: an unrecognized project-type symbol falls through to the unknown branch." + (let ((cands (cj/--f4-candidates 'fictional-type))) + (should (= (length cands) 1)) + (should (eq (cdar cands) 'compile-plain)))) + +;;; Error Cases + +(ert-deftest test-dev-fkeys-f4-candidates-nil-falls-back-to-unknown () + "Error: nil project-type falls through to the unknown branch." + (let ((cands (cj/--f4-candidates nil))) + (should (= (length cands) 1)) + (should (eq (cdar cands) 'compile-plain)))) + +(provide 'test-dev-fkeys--f4-candidates) +;;; test-dev-fkeys--f4-candidates.el ends here diff --git a/tests/test-dev-fkeys--f4-clean-rebuild-impl.el b/tests/test-dev-fkeys--f4-clean-rebuild-impl.el new file mode 100644 index 00000000..27c7c56a --- /dev/null +++ b/tests/test-dev-fkeys--f4-clean-rebuild-impl.el @@ -0,0 +1,118 @@ +;;; test-dev-fkeys--f4-clean-rebuild-impl.el --- Tests for cj/--f4-clean-rebuild-impl -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the "Clean + Rebuild" action handler. Runs the heuristic clean +;; command via `compile' from the project root, then chains +;; `projectile-compile-project' on success via the one-shot finish hook. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +(defmacro test-dev-fkeys-cr--with-project (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-cr-" 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-clean-rebuild-impl-runs-derived-clean-cmd () + "Normal: handler invokes `compile' with the heuristic clean command for the +project marker present at ROOT. + +Components integrated: +- `cj/--f4-clean-rebuild-impl' (unit under test) +- `cj/--f4-derive-clean-cmd' (real) +- `compile' (MOCKED — captures the command string) +- `projectile-compile-project' (MOCKED — no-op) +- `compilation-finish-functions' (real, scoped via let)" + (test-dev-fkeys-cr--with-project '("Makefile") + (let ((compile-calls nil) + (compilation-finish-functions nil)) + (cl-letf (((symbol-function 'compile) + (lambda (cmd) (push cmd compile-calls))) + ((symbol-function 'projectile-compile-project) + (lambda (_arg) nil))) + (cj/--f4-clean-rebuild-impl root) + (should (equal compile-calls '("make clean"))))))) + +(ert-deftest test-dev-fkeys-clean-rebuild-impl-installs-finish-hook () + "Normal: handler installs exactly one hook in `compilation-finish-functions'." + (test-dev-fkeys-cr--with-project '("go.mod") + (let ((compilation-finish-functions nil)) + (cl-letf (((symbol-function 'compile) (lambda (_cmd) nil)) + ((symbol-function 'projectile-compile-project) + (lambda (_arg) nil))) + (cj/--f4-clean-rebuild-impl root) + (should (= (length compilation-finish-functions) 1)))))) + +(ert-deftest test-dev-fkeys-clean-rebuild-impl-hook-runs-projectile-compile-on-success () + "Normal: when the clean step finishes successfully, the installed hook +calls `projectile-compile-project' to do the rebuild." + (test-dev-fkeys-cr--with-project '("Cargo.toml") + (let ((compile-calls 0) + (compilation-finish-functions nil)) + (cl-letf (((symbol-function 'compile) (lambda (_cmd) nil)) + ((symbol-function 'projectile-compile-project) + (lambda (_arg) (cl-incf compile-calls)))) + (cj/--f4-clean-rebuild-impl root) + (run-hook-with-args 'compilation-finish-functions nil "finished\n") + (should (= compile-calls 1)))))) + +(ert-deftest test-dev-fkeys-clean-rebuild-impl-runs-clean-from-project-root () + "Normal: the clean compile runs with default-directory bound to ROOT." + (test-dev-fkeys-cr--with-project '("Eask") + (let ((seen-dir nil) + (compilation-finish-functions nil)) + (cl-letf (((symbol-function 'compile) + (lambda (_cmd) (setq seen-dir default-directory))) + ((symbol-function 'projectile-compile-project) + (lambda (_arg) nil))) + (cj/--f4-clean-rebuild-impl root) + (should (string= (file-name-as-directory seen-dir) + (file-name-as-directory root))))))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-clean-rebuild-impl-hook-skips-rebuild-on-failure () + "Boundary: when the clean step fails, projectile-compile-project does not run." + (test-dev-fkeys-cr--with-project '("Makefile") + (let ((compile-calls 0) + (compilation-finish-functions nil)) + (cl-letf (((symbol-function 'compile) (lambda (_cmd) nil)) + ((symbol-function 'projectile-compile-project) + (lambda (_arg) (cl-incf compile-calls)))) + (cj/--f4-clean-rebuild-impl root) + (run-hook-with-args 'compilation-finish-functions nil "exited abnormally\n") + (should (= compile-calls 0)))))) + +;;; Error Cases + +(ert-deftest test-dev-fkeys-clean-rebuild-impl-no-clean-cmd-signals-user-error () + "Error: a project root with no recognized markers signals a user-error +rather than silently running nothing." + (test-dev-fkeys-cr--with-project '("README.md") + (cl-letf (((symbol-function 'compile) (lambda (_cmd) nil)) + ((symbol-function 'projectile-compile-project) + (lambda (_arg) nil))) + (should-error (cj/--f4-clean-rebuild-impl root) :type 'user-error)))) + +(ert-deftest test-dev-fkeys-clean-rebuild-impl-nil-root-signals-user-error () + "Error: a nil root signals a user-error (no project detected)." + (cl-letf (((symbol-function 'compile) (lambda (_cmd) nil)) + ((symbol-function 'projectile-compile-project) + (lambda (_arg) nil))) + (should-error (cj/--f4-clean-rebuild-impl nil) :type 'user-error))) + +(provide 'test-dev-fkeys--f4-clean-rebuild-impl) +;;; test-dev-fkeys--f4-clean-rebuild-impl.el ends here diff --git a/tests/test-dev-fkeys--f4-clean-rebuild.el b/tests/test-dev-fkeys--f4-clean-rebuild.el new file mode 100644 index 00000000..040ce930 --- /dev/null +++ b/tests/test-dev-fkeys--f4-clean-rebuild.el @@ -0,0 +1,61 @@ +;;; test-dev-fkeys--f4-clean-rebuild.el --- Smoke tests for cj/f4-clean-rebuild -*- lexical-binding: t -*- + +;;; Commentary: +;; Smoke tests for the M-F4 fast path. On a compiled project, runs the +;; clean-rebuild handler. Interpreted and unknown projects get a no-op +;; message — no rebuild attempt, no error. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +(defmacro test-dev-fkeys-cr-w--with-project (markers &rest body) + "Set up a temp project with MARKERS, bind ROOT, run BODY, clean up." + (declare (indent 1)) + `(let ((root (make-temp-file "test-dev-fkeys-cr-w-" 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-f4-clean-rebuild-compiled-project-runs-impl-with-root () + "Normal: on a compiled project, calls cj/--f4-clean-rebuild-impl with the +project root." + (test-dev-fkeys-cr-w--with-project '("Makefile") + (let (received-root) + (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () root)) + ((symbol-function 'cj/--f4-clean-rebuild-impl) + (lambda (r) (setq received-root r)))) + (cj/f4-clean-rebuild) + (should (string= received-root root)))))) + +(ert-deftest test-dev-fkeys-f4-clean-rebuild-interpreted-project-skips-impl () + "Normal: on an interpreted project, the impl handler is not invoked." + (test-dev-fkeys-cr-w--with-project '("pyproject.toml") + (let ((calls 0)) + (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () root)) + ((symbol-function 'cj/--f4-clean-rebuild-impl) + (lambda (_r) (cl-incf calls)))) + (cj/f4-clean-rebuild) + (should (= calls 0)))))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-f4-clean-rebuild-unknown-project-skips-impl () + "Boundary: outside any project, the impl handler is not invoked." + (let ((calls 0)) + (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () nil)) + ((symbol-function 'cj/--f4-clean-rebuild-impl) + (lambda (_r) (cl-incf calls)))) + (cj/f4-clean-rebuild) + (should (= calls 0))))) + +(provide 'test-dev-fkeys--f4-clean-rebuild) +;;; test-dev-fkeys--f4-clean-rebuild.el ends here diff --git a/tests/test-dev-fkeys--f4-compile-and-run-impl.el b/tests/test-dev-fkeys--f4-compile-and-run-impl.el new file mode 100644 index 00000000..d59a6cd6 --- /dev/null +++ b/tests/test-dev-fkeys--f4-compile-and-run-impl.el @@ -0,0 +1,75 @@ +;;; test-dev-fkeys--f4-compile-and-run-impl.el --- Tests for cj/--f4-compile-and-run-impl -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the "Compile + Run" action handler. After kicking off the +;; compile, attaches a one-shot `compilation-finish-functions' hook that +;; runs the project on success. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +;;; Normal Cases + +(ert-deftest test-dev-fkeys-compile-and-run-impl-invokes-projectile-compile () + "Normal: handler calls `projectile-compile-project'. + +Components integrated: +- `cj/--f4-compile-and-run-impl' (unit under test) +- `projectile-compile-project' (MOCKED via cl-letf) +- `compilation-finish-functions' (real, scoped via let)" + (let ((compile-calls 0) + (compilation-finish-functions nil)) + (cl-letf (((symbol-function 'projectile-compile-project) + (lambda (_arg) (cl-incf compile-calls)))) + (cj/--f4-compile-and-run-impl) + (should (= compile-calls 1))))) + +(ert-deftest test-dev-fkeys-compile-and-run-impl-installs-finish-hook () + "Normal: handler installs exactly one hook in `compilation-finish-functions'." + (let ((compilation-finish-functions nil)) + (cl-letf (((symbol-function 'projectile-compile-project) + (lambda (_arg) nil))) + (cj/--f4-compile-and-run-impl) + (should (= (length compilation-finish-functions) 1))))) + +(ert-deftest test-dev-fkeys-compile-and-run-impl-hook-runs-projectile-run-on-success () + "Normal: when the compile finishes successfully, the installed hook calls +`projectile-run-project'. + +Components integrated: +- `cj/--f4-compile-and-run-impl' (unit under test) +- `projectile-compile-project' (MOCKED — no-op) +- `projectile-run-project' (MOCKED — counts calls) +- `compilation-finish-functions' (real) +- `run-hook-with-args' (real — simulates compile.el firing the hook)" + (let ((run-calls 0) + (compilation-finish-functions nil)) + (cl-letf (((symbol-function 'projectile-compile-project) + (lambda (_arg) nil)) + ((symbol-function 'projectile-run-project) + (lambda (_arg) (cl-incf run-calls)))) + (cj/--f4-compile-and-run-impl) + (run-hook-with-args 'compilation-finish-functions nil "finished\n") + (should (= run-calls 1))))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-compile-and-run-impl-hook-skips-projectile-run-on-failure () + "Boundary: when the compile fails, projectile-run-project must not run. +The hook still self-removes (covered in the make-once-hook tests)." + (let ((run-calls 0) + (compilation-finish-functions nil)) + (cl-letf (((symbol-function 'projectile-compile-project) + (lambda (_arg) nil)) + ((symbol-function 'projectile-run-project) + (lambda (_arg) (cl-incf run-calls)))) + (cj/--f4-compile-and-run-impl) + (run-hook-with-args 'compilation-finish-functions nil "exited abnormally\n") + (should (= run-calls 0))))) + +(provide 'test-dev-fkeys--f4-compile-and-run-impl) +;;; test-dev-fkeys--f4-compile-and-run-impl.el ends here diff --git a/tests/test-dev-fkeys--f4-compile-and-run.el b/tests/test-dev-fkeys--f4-compile-and-run.el new file mode 100644 index 00000000..3e0da877 --- /dev/null +++ b/tests/test-dev-fkeys--f4-compile-and-run.el @@ -0,0 +1,94 @@ +;;; test-dev-fkeys--f4-compile-and-run.el --- Smoke tests for cj/f4-compile-and-run -*- lexical-binding: t -*- + +;;; Commentary: +;; Smoke tests for the interactive F4 wrapper. The wrapper: +;; +;; 1. Resolves the project root. +;; 2. Detects project type from markers. +;; 3. Builds the candidate list. +;; 4. Prompts via completing-read. +;; 5. Looks up the chosen label's action. +;; 6. Dispatches. +;; +;; Per the elisp-testing rule on Interactive vs Internal split, the heavy +;; lifting is in `cj/--f4-dispatch' and the helpers — those are tested +;; directly in their own files. This file just confirms the wrapper wires +;; the pieces together: prompt fires, the chosen label routes to the right +;; action symbol. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +(defmacro test-dev-fkeys-f4--with-project (markers &rest body) + "Set up a temp project with MARKERS, bind ROOT, run BODY, clean up." + (declare (indent 1)) + `(let ((root (make-temp-file "test-dev-fkeys-f4-" 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-f4-compile-and-run-prompts-with-completing-read () + "Normal: the wrapper invokes completing-read with the project's candidate labels. + +Components integrated: +- `cj/f4-compile-and-run' (unit under test) +- `cj/--f4-project-root' (MOCKED — returns the temp project root) +- `cj/--detect-project-type' (real) +- `cj/--f4-candidates' (real) +- `completing-read' (MOCKED — captures candidates and returns the default) +- `cj/--f4-dispatch' (MOCKED — captures the action it received)" + (test-dev-fkeys-f4--with-project '("go.mod") + (let (seen-candidates seen-action) + (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () root)) + ((symbol-function 'completing-read) + (lambda (_prompt collection &rest _) + (setq seen-candidates collection) + (car collection))) + ((symbol-function 'cj/--f4-dispatch) + (lambda (action) (setq seen-action action)))) + (cj/f4-compile-and-run) + ;; Compiled-project candidates are the four labels. + (should (member "Compile + Run" seen-candidates)) + (should (member "Compile" seen-candidates)) + (should (member "Run" seen-candidates)) + (should (member "Clean + Rebuild" seen-candidates)) + ;; Default (first label) is "Compile + Run", which routes to + ;; the compile-and-run action. + (should (eq seen-action 'compile-and-run)))))) + +(ert-deftest test-dev-fkeys-f4-compile-and-run-routes-chosen-label-to-action () + "Normal: a non-default label selection routes to the right action." + (test-dev-fkeys-f4--with-project '("Cargo.toml") + (let (seen-action) + (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () root)) + ((symbol-function 'completing-read) + (lambda (&rest _) "Run")) + ((symbol-function 'cj/--f4-dispatch) + (lambda (action) (setq seen-action action)))) + (cj/f4-compile-and-run) + (should (eq seen-action 'run-only)))))) + +(ert-deftest test-dev-fkeys-f4-compile-and-run-interpreted-project-shows-run-only () + "Normal: an interpreted project's menu has only the Run candidate." + (test-dev-fkeys-f4--with-project '("pyproject.toml") + (let (seen-candidates) + (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () root)) + ((symbol-function 'completing-read) + (lambda (_prompt collection &rest _) + (setq seen-candidates collection) + (car collection))) + ((symbol-function 'cj/--f4-dispatch) (lambda (_action) nil))) + (cj/f4-compile-and-run) + (should (equal seen-candidates '("Run"))))))) + +(provide 'test-dev-fkeys--f4-compile-and-run) +;;; test-dev-fkeys--f4-compile-and-run.el ends here diff --git a/tests/test-dev-fkeys--f4-compile-only.el b/tests/test-dev-fkeys--f4-compile-only.el new file mode 100644 index 00000000..b0eec367 --- /dev/null +++ b/tests/test-dev-fkeys--f4-compile-only.el @@ -0,0 +1,61 @@ +;;; test-dev-fkeys--f4-compile-only.el --- Smoke tests for cj/f4-compile-only -*- lexical-binding: t -*- + +;;; Commentary: +;; Smoke tests for the C-F4 fast path. On a compiled project, calls +;; `projectile-compile-project'. On an interpreted project, messages +;; "not a compiled language". With no project detected, falls back to +;; plain `compile'. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +(defmacro test-dev-fkeys-co--with-project (markers &rest body) + "Set up a temp project with MARKERS, bind ROOT, run BODY, clean up." + (declare (indent 1)) + `(let ((root (make-temp-file "test-dev-fkeys-co-" 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-f4-compile-only-compiled-project-runs-projectile-compile () + "Normal: on a compiled project, calls projectile-compile-project." + (test-dev-fkeys-co--with-project '("go.mod") + (let ((calls 0)) + (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () root)) + ((symbol-function 'projectile-compile-project) + (lambda (_arg) (cl-incf calls)))) + (cj/f4-compile-only) + (should (= calls 1)))))) + +(ert-deftest test-dev-fkeys-f4-compile-only-interpreted-project-skips-compile () + "Normal: on an interpreted project, projectile-compile-project does not run." + (test-dev-fkeys-co--with-project '("pyproject.toml") + (let ((calls 0)) + (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () root)) + ((symbol-function 'projectile-compile-project) + (lambda (_arg) (cl-incf calls)))) + (cj/f4-compile-only) + (should (= calls 0)))))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-f4-compile-only-unknown-project-falls-back-to-compile () + "Boundary: outside any project, falls back to interactive `compile'." + (let (received-fn) + (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () nil)) + ((symbol-function 'call-interactively) + (lambda (fn &rest _) (setq received-fn fn)))) + (cj/f4-compile-only) + (should (eq received-fn #'compile))))) + +(provide 'test-dev-fkeys--f4-compile-only) +;;; test-dev-fkeys--f4-compile-only.el ends here 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 diff --git a/tests/test-dev-fkeys--f4-dispatch.el b/tests/test-dev-fkeys--f4-dispatch.el new file mode 100644 index 00000000..774daebf --- /dev/null +++ b/tests/test-dev-fkeys--f4-dispatch.el @@ -0,0 +1,78 @@ +;;; test-dev-fkeys--f4-dispatch.el --- Tests for cj/--f4-dispatch -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the dispatch router. Each known action symbol routes to the +;; corresponding command. Unknown actions raise user-error. The action +;; handlers themselves are tested in their own files; this file only +;; verifies the routing layer. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +;;; Normal Cases + +(ert-deftest test-dev-fkeys-dispatch-compile-only-calls-projectile-compile () + "Normal: 'compile-only routes to projectile-compile-project." + (let ((calls 0)) + (cl-letf (((symbol-function 'projectile-compile-project) + (lambda (_arg) (cl-incf calls)))) + (cj/--f4-dispatch 'compile-only) + (should (= calls 1))))) + +(ert-deftest test-dev-fkeys-dispatch-run-only-calls-projectile-run () + "Normal: 'run-only routes to projectile-run-project." + (let ((calls 0)) + (cl-letf (((symbol-function 'projectile-run-project) + (lambda (_arg) (cl-incf calls)))) + (cj/--f4-dispatch 'run-only) + (should (= calls 1))))) + +(ert-deftest test-dev-fkeys-dispatch-compile-and-run-routes-to-impl () + "Normal: 'compile-and-run routes to cj/--f4-compile-and-run-impl." + (let ((calls 0)) + (cl-letf (((symbol-function 'cj/--f4-compile-and-run-impl) + (lambda () (cl-incf calls)))) + (cj/--f4-dispatch 'compile-and-run) + (should (= calls 1))))) + +(ert-deftest test-dev-fkeys-dispatch-clean-rebuild-routes-to-impl-with-root () + "Normal: 'clean-rebuild routes to cj/--f4-clean-rebuild-impl with the project root. + +Components integrated: +- `cj/--f4-dispatch' (unit under test) +- `cj/--f4-project-root' (MOCKED — returns a fake path) +- `cj/--f4-clean-rebuild-impl' (MOCKED — captures the ROOT it received)" + (let (received-root) + (cl-letf (((symbol-function 'cj/--f4-project-root) + (lambda () "/fake/project/")) + ((symbol-function 'cj/--f4-clean-rebuild-impl) + (lambda (root) (setq received-root root)))) + (cj/--f4-dispatch 'clean-rebuild) + (should (string= received-root "/fake/project/"))))) + +(ert-deftest test-dev-fkeys-dispatch-compile-plain-uses-call-interactively-on-compile () + "Normal: 'compile-plain invokes `compile' interactively (so the user is +prompted for a command). We check that `call-interactively' fires with +the symbol `compile'." + (let (received-fn) + (cl-letf (((symbol-function 'call-interactively) + (lambda (fn &rest _) (setq received-fn fn)))) + (cj/--f4-dispatch 'compile-plain) + (should (eq received-fn #'compile))))) + +;;; Error Cases + +(ert-deftest test-dev-fkeys-dispatch-unknown-action-signals-user-error () + "Error: dispatch on an unknown symbol raises user-error." + (should-error (cj/--f4-dispatch 'fictional-action) :type 'user-error)) + +(ert-deftest test-dev-fkeys-dispatch-nil-action-signals-user-error () + "Error: nil action raises user-error (defensive against bad menu data)." + (should-error (cj/--f4-dispatch nil) :type 'user-error)) + +(provide 'test-dev-fkeys--f4-dispatch) +;;; test-dev-fkeys--f4-dispatch.el ends here diff --git a/tests/test-dev-fkeys--f4-make-once-hook.el b/tests/test-dev-fkeys--f4-make-once-hook.el new file mode 100644 index 00000000..b6c71dd7 --- /dev/null +++ b/tests/test-dev-fkeys--f4-make-once-hook.el @@ -0,0 +1,115 @@ +;;; test-dev-fkeys--f4-make-once-hook.el --- Tests for cj/--f4-make-once-hook -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the one-shot `compilation-finish-functions' hook builder used by +;; "Compile + Run" and "Clean + Rebuild" to chain a follow-up command after +;; a successful compile. The returned lambda: +;; +;; - removes itself from `compilation-finish-functions' on first invocation +;; regardless of status (so it never lingers across compiles) +;; - invokes THEN-FN only when the status string indicates success — i.e. +;; `string-prefix-p \"finished\"' matches. +;; +;; The status conventions come from the compile.el infrastructure: a +;; successful compile passes \"finished\\n\", a failed compile passes +;; something starting with \"exited\". + +;;; Code: + +(require 'ert) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +;;; Normal Cases + +(ert-deftest test-dev-fkeys-make-once-hook-success-status-calls-then-fn () + "Normal: status starting with 'finished' invokes THEN-FN once." + (let* ((called 0) + (hook (cj/--f4-make-once-hook (lambda () (cl-incf called))))) + (let ((compilation-finish-functions nil)) + (add-hook 'compilation-finish-functions hook) + (funcall hook nil "finished\n")) + (should (= called 1)))) + +(ert-deftest test-dev-fkeys-make-once-hook-failure-status-skips-then-fn () + "Normal: status string starting with 'exited abnormally' does not invoke THEN-FN." + (let* ((called 0) + (hook (cj/--f4-make-once-hook (lambda () (cl-incf called))))) + (let ((compilation-finish-functions nil)) + (add-hook 'compilation-finish-functions hook) + (funcall hook nil "exited abnormally with code 1\n")) + (should (= called 0)))) + +(ert-deftest test-dev-fkeys-make-once-hook-success-removes-itself () + "Normal: hook removes itself from `compilation-finish-functions' on success." + (let* ((hook (cj/--f4-make-once-hook (lambda () nil))) + (compilation-finish-functions (list hook))) + (should (memq hook compilation-finish-functions)) + (funcall hook nil "finished\n") + (should-not (memq hook compilation-finish-functions)))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-make-once-hook-failure-also-removes-itself () + "Boundary: hook removes itself even on failure, so it never fires on the +next compile. THEN-FN is not invoked, but the hook is still cleaned up." + (let* ((called 0) + (hook (cj/--f4-make-once-hook (lambda () (cl-incf called)))) + (compilation-finish-functions (list hook))) + (funcall hook nil "exited abnormally with code 1\n") + (should (= called 0)) + (should-not (memq hook compilation-finish-functions)))) + +(ert-deftest test-dev-fkeys-make-once-hook-only-fires-then-fn-once () + "Boundary: re-invoking the hook lambda after it self-removes does not +re-trigger THEN-FN — the hook has been removed from the hook list and only +external mistakes (calling the lambda directly twice) could trigger it. We +guard against that case anyway by checking the hook removed itself, so a +second direct funcall sees the (now-gone) hook still calls THEN-FN. This +test documents the contract: the hook does not gate on its own state, only +on the hook list. So the SECOND direct funcall WILL call THEN-FN. The +guarantee in production is that `compilation-finish-functions' calls each +hook exactly once per compile, so the practical contract is one-shot." + (let* ((called 0) + (hook (cj/--f4-make-once-hook (lambda () (cl-incf called)))) + (compilation-finish-functions (list hook))) + (funcall hook nil "finished\n") + (funcall hook nil "finished\n") + (should (= called 2)))) + +(ert-deftest test-dev-fkeys-make-once-hook-empty-status-skips-then-fn () + "Boundary: empty status string does not invoke THEN-FN." + (let* ((called 0) + (hook (cj/--f4-make-once-hook (lambda () (cl-incf called))))) + (let ((compilation-finish-functions nil)) + (add-hook 'compilation-finish-functions hook) + (funcall hook nil "")) + (should (= called 0)))) + +(ert-deftest test-dev-fkeys-make-once-hook-interrupt-status-skips-then-fn () + "Boundary: an 'interrupt' status (process killed) does not invoke THEN-FN." + (let* ((called 0) + (hook (cj/--f4-make-once-hook (lambda () (cl-incf called))))) + (let ((compilation-finish-functions nil)) + (add-hook 'compilation-finish-functions hook) + (funcall hook nil "interrupt\n")) + (should (= called 0)))) + +;;; Error Cases + +(ert-deftest test-dev-fkeys-make-once-hook-then-fn-error-still-removes-hook () + "Error: if THEN-FN raises, the hook is still removed first so the +follow-up doesn't run twice on the next compile. + +Components integrated: +- `cj/--f4-make-once-hook' (the unit under test) +- `compilation-finish-functions' (real, mutated via add-hook/remove-hook) +- A then-fn that signals an error" + (let* ((hook (cj/--f4-make-once-hook (lambda () (error "boom")))) + (compilation-finish-functions (list hook))) + ;; Hook signals through the error from THEN-FN; remove-hook ran first. + (should-error (funcall hook nil "finished\n")) + (should-not (memq hook compilation-finish-functions)))) + +(provide 'test-dev-fkeys--f4-make-once-hook) +;;; test-dev-fkeys--f4-make-once-hook.el ends here diff --git a/tests/test-dev-fkeys--f4-project-root.el b/tests/test-dev-fkeys--f4-project-root.el new file mode 100644 index 00000000..617bb9e1 --- /dev/null +++ b/tests/test-dev-fkeys--f4-project-root.el @@ -0,0 +1,51 @@ +;;; test-dev-fkeys--f4-project-root.el --- Tests for cj/--f4-project-root -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the projectile-root wrapper. Projectile's +;; `projectile-project-root' raises an error in some configurations when +;; called outside a known project; this wrapper degrades to nil so the F4 +;; dispatcher can route to the 'unknown branch instead of crashing. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +;;; Normal Cases + +(ert-deftest test-dev-fkeys-f4-project-root-returns-projectile-value () + "Normal: returns whatever `projectile-project-root' returns when fbound." + (cl-letf (((symbol-function 'projectile-project-root) + (lambda () "/some/project/"))) + (should (string= (cj/--f4-project-root) "/some/project/")))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-f4-project-root-returns-nil-when-projectile-unbound () + "Boundary: returns nil when projectile is not loaded. + +Components integrated: +- `cj/--f4-project-root' (unit under test) +- `projectile-project-root' (MOCKED — fmakunbound to simulate absence)" + (let ((had-projectile (fboundp 'projectile-project-root)) + (saved (and (fboundp 'projectile-project-root) + (symbol-function 'projectile-project-root)))) + (unwind-protect + (progn + (when had-projectile (fmakunbound 'projectile-project-root)) + (should (null (cj/--f4-project-root)))) + (when had-projectile + (fset 'projectile-project-root saved))))) + +;;; Error Cases + +(ert-deftest test-dev-fkeys-f4-project-root-returns-nil-on-projectile-error () + "Error: returns nil when `projectile-project-root' signals an error." + (cl-letf (((symbol-function 'projectile-project-root) + (lambda () (error "Outside a known project")))) + (should (null (cj/--f4-project-root))))) + +(provide 'test-dev-fkeys--f4-project-root) +;;; test-dev-fkeys--f4-project-root.el ends here |
