summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test-dev-fkeys--projectile-around-revert.el14
-rw-r--r--tests/test-dev-fkeys--projectile-capture-cmd.el27
-rw-r--r--tests/test-dev-fkeys--projectile-revert-on-fail.el65
3 files changed, 36 insertions, 70 deletions
diff --git a/tests/test-dev-fkeys--projectile-around-revert.el b/tests/test-dev-fkeys--projectile-around-revert.el
index 012c4258..229ff723 100644
--- a/tests/test-dev-fkeys--projectile-around-revert.el
+++ b/tests/test-dev-fkeys--projectile-around-revert.el
@@ -5,7 +5,7 @@
;; to projectile cmd runners. The advice:
;;
;; 1. Captures the prior cached cmd via `cj/--projectile-capture-cmd'.
-;; 2. Adds `cj/--projectile-revert-on-fail' to `compilation-finish-functions'.
+;; 2. Adds a buffer-local revert hook to `compilation-finish-functions'.
;; 3. Calls ORIG-FN with ARGS so projectile's normal flow proceeds.
;;; Code:
@@ -22,7 +22,6 @@
(ert-deftest test-dev-fkeys-projectile-around-revert-invokes-orig-fn ()
"Normal: advice calls the wrapped function with its args."
(let ((calls nil)
- (cj/--projectile-revert-state nil)
(compilation-finish-functions nil)
(projectile-compile-cmd-map (make-hash-table :test 'equal)))
(cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () "/p/")))
@@ -34,8 +33,7 @@
(ert-deftest test-dev-fkeys-projectile-around-revert-captures-prior ()
"Normal: advice captures the prior cmd into the buffer-local hook."
- (let ((cj/--projectile-revert-state nil)
- (compilation-finish-functions nil)
+ (let ((compilation-finish-functions nil)
(projectile-compile-cmd-map (make-hash-table :test 'equal)))
(puthash "/p/" "make build" projectile-compile-cmd-map)
(cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () "/p/")))
@@ -55,8 +53,7 @@
(ert-deftest test-dev-fkeys-projectile-around-revert-installs-finish-hook ()
"Normal: advice adds a buffer-local revert hook to the compilation buffer."
- (let ((cj/--projectile-revert-state nil)
- (compilation-finish-functions nil)
+ (let ((compilation-finish-functions nil)
(projectile-compile-cmd-map (make-hash-table :test 'equal)))
(puthash "/p/" "make build" projectile-compile-cmd-map)
(cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () "/p/")))
@@ -74,8 +71,7 @@
(ert-deftest test-dev-fkeys-projectile-around-revert-overlapping-compiles-use-own-state ()
"Regression: overlapping compiles finishing out of order use their own state."
- (let ((cj/--projectile-revert-state nil)
- (compilation-finish-functions nil)
+ (let ((compilation-finish-functions nil)
(projectile-compile-cmd-map (make-hash-table :test 'equal))
(roots '("/one/" "/two/")))
(puthash "/one/" "make one" projectile-compile-cmd-map)
@@ -115,14 +111,12 @@
"Boundary: no project root → capture is a no-op, orig-fn still runs.
The state stays nil so the finish hook will be a no-op too."
(let ((calls 0)
- (cj/--projectile-revert-state nil)
(compilation-finish-functions nil))
(cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () nil)))
(cj/--projectile-around-revert
'projectile-compile-cmd-map
(lambda (&rest _) (cl-incf calls))))
(should (= calls 1))
- (should (null cj/--projectile-revert-state))
(should-not compilation-finish-functions)))
(provide 'test-dev-fkeys--projectile-around-revert)
diff --git a/tests/test-dev-fkeys--projectile-capture-cmd.el b/tests/test-dev-fkeys--projectile-capture-cmd.el
index bc4c7684..85d4603f 100644
--- a/tests/test-dev-fkeys--projectile-capture-cmd.el
+++ b/tests/test-dev-fkeys--projectile-capture-cmd.el
@@ -23,8 +23,7 @@
(ert-deftest test-dev-fkeys-projectile-capture-cmd-stores-prior-value ()
"Normal: captures the cached cmd at the project root into the state plist."
- (let* ((cj/--projectile-revert-state nil)
- (projectile-compile-cmd-map (make-hash-table :test 'equal))
+ (let* ((projectile-compile-cmd-map (make-hash-table :test 'equal))
state)
(puthash "/p/" "make build" projectile-compile-cmd-map)
(cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () "/p/")))
@@ -32,43 +31,37 @@
(should (equal (plist-get state :map)
'projectile-compile-cmd-map))
(should (equal (plist-get state :root) "/p/"))
- (should (equal (plist-get state :prior) "make build"))
- (should (null cj/--projectile-revert-state))))
+ (should (equal (plist-get state :prior) "make build"))))
(ert-deftest test-dev-fkeys-projectile-capture-cmd-no-prior-stores-nil ()
"Normal: when no cmd is cached, captures :prior nil — distinct from
\"didn't capture at all\" because :map and :root are still set."
- (let* ((cj/--projectile-revert-state nil)
- (projectile-test-cmd-map (make-hash-table :test 'equal))
+ (let* ((projectile-test-cmd-map (make-hash-table :test 'equal))
state)
(cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () "/p/")))
(setq state (cj/--projectile-capture-cmd 'projectile-test-cmd-map)))
(should (eq (plist-get state :map)
'projectile-test-cmd-map))
- (should (null (plist-get state :prior)))
- (should (null cj/--projectile-revert-state))))
+ (should (null (plist-get state :prior)))))
;;; Boundary Cases
(ert-deftest test-dev-fkeys-projectile-capture-cmd-nil-root-leaves-state-nil ()
"Boundary: when no project root resolves, state stays nil so the
finish hook treats it as a no-op."
- (let ((cj/--projectile-revert-state nil)
- (projectile-compile-cmd-map (make-hash-table :test 'equal)))
+ (let ((projectile-compile-cmd-map (make-hash-table :test 'equal)))
(cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () nil)))
- (cj/--projectile-capture-cmd 'projectile-compile-cmd-map))
- (should (null cj/--projectile-revert-state))))
+ (should-not (cj/--projectile-capture-cmd 'projectile-compile-cmd-map)))))
;;; Error Cases
(ert-deftest test-dev-fkeys-projectile-capture-cmd-unbound-map-leaves-state-nil ()
"Error: when the cmd-map symbol is unbound (projectile not loaded),
state stays nil and no error is raised."
- (let ((cj/--projectile-revert-state nil))
- (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () "/p/")))
- ;; Use a clearly-unbound symbol to simulate projectile-not-loaded.
- (cj/--projectile-capture-cmd 'cj-test--definitely-not-bound-xyzzy))
- (should (null cj/--projectile-revert-state))))
+ (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () "/p/")))
+ ;; Use a clearly-unbound symbol to simulate projectile-not-loaded.
+ (should-not
+ (cj/--projectile-capture-cmd 'cj-test--definitely-not-bound-xyzzy))))
(provide 'test-dev-fkeys--projectile-capture-cmd)
;;; test-dev-fkeys--projectile-capture-cmd.el ends here
diff --git a/tests/test-dev-fkeys--projectile-revert-on-fail.el b/tests/test-dev-fkeys--projectile-revert-on-fail.el
index 6fadd539..78e4c815 100644
--- a/tests/test-dev-fkeys--projectile-revert-on-fail.el
+++ b/tests/test-dev-fkeys--projectile-revert-on-fail.el
@@ -1,11 +1,9 @@
-;;; test-dev-fkeys--projectile-revert-on-fail.el --- Tests for cj/--projectile-revert-on-fail -*- lexical-binding: t -*-
+;;; test-dev-fkeys--projectile-revert-on-fail.el --- Tests for projectile revert decisions -*- lexical-binding: t -*-
;;; Commentary:
-;; Tests for the compilation-finish hook that reverts projectile's
-;; per-project cache when a build/test failed AND the cmd was modified.
-;; Test-fails-because-of-real-bug (cmd unchanged) leaves the cache alone.
-;; The hook also self-removes from `compilation-finish-functions' on
-;; first invocation and clears `cj/--projectile-revert-state'.
+;; Tests for reverting Projectile's per-project cache when a build/test failed
+;; AND the command was modified. Test-fails-because-of-real-bug (cmd unchanged)
+;; leaves the cache alone.
;;; Code:
@@ -18,87 +16,68 @@
;;; Normal Cases
-(ert-deftest test-dev-fkeys-projectile-revert-on-fail-failure-and-modified-reverts ()
+(ert-deftest test-dev-fkeys-projectile-revert-state-on-fail-failure-and-modified-reverts ()
"Normal: failure status + cmd modified from prior → revert to prior."
(let* ((projectile-compile-cmd-map (make-hash-table :test 'equal))
- (cj/--projectile-revert-state
+ (state
(list :map 'projectile-compile-cmd-map
:root "/p/"
:prior "make build")))
(puthash "/p/" "make buidl" projectile-compile-cmd-map)
- (cj/--projectile-revert-on-fail nil "exited abnormally with code 2\n")
+ (cj/--projectile-revert-state-on-fail
+ state "exited abnormally with code 2\n")
(should (string= (gethash "/p/" projectile-compile-cmd-map) "make build"))))
-(ert-deftest test-dev-fkeys-projectile-revert-on-fail-success-leaves-cache ()
+(ert-deftest test-dev-fkeys-projectile-revert-state-on-fail-success-leaves-cache ()
"Normal: success status → no revert, cache keeps the modified cmd."
(let* ((projectile-compile-cmd-map (make-hash-table :test 'equal))
- (cj/--projectile-revert-state
+ (state
(list :map 'projectile-compile-cmd-map
:root "/p/"
:prior "make build")))
(puthash "/p/" "make build-fast" projectile-compile-cmd-map)
- (cj/--projectile-revert-on-fail nil "finished\n")
+ (cj/--projectile-revert-state-on-fail state "finished\n")
(should (string= (gethash "/p/" projectile-compile-cmd-map) "make build-fast"))))
-(ert-deftest test-dev-fkeys-projectile-revert-on-fail-clears-state ()
- "Normal: hook clears `cj/--projectile-revert-state' regardless of outcome."
- (let* ((projectile-compile-cmd-map (make-hash-table :test 'equal))
- (cj/--projectile-revert-state
- (list :map 'projectile-compile-cmd-map :root "/p/" :prior "x")))
- (cj/--projectile-revert-on-fail nil "finished\n")
- (should (null cj/--projectile-revert-state))))
-
-(ert-deftest test-dev-fkeys-projectile-revert-on-fail-removes-itself ()
- "Normal: hook removes itself from `compilation-finish-functions'."
- (let* ((projectile-compile-cmd-map (make-hash-table :test 'equal))
- (cj/--projectile-revert-state
- (list :map 'projectile-compile-cmd-map :root "/p/" :prior "x"))
- (compilation-finish-functions
- (list #'cj/--projectile-revert-on-fail)))
- (cj/--projectile-revert-on-fail nil "finished\n")
- (should-not (member #'cj/--projectile-revert-on-fail
- compilation-finish-functions))))
-
;;; Boundary Cases
-(ert-deftest test-dev-fkeys-projectile-revert-on-fail-failure-but-unchanged-no-revert ()
+(ert-deftest test-dev-fkeys-projectile-revert-state-on-fail-failure-but-unchanged-no-revert ()
"Boundary: failure status + cmd unchanged from prior → no revert.
This is the test-fails-because-of-real-bug case. Don't flap the cache.
Components integrated:
-- `cj/--projectile-revert-on-fail' (unit under test)
-- `cj/--projectile-revert-state' (real, scoped via let)
+- `cj/--projectile-revert-state-on-fail' (unit under test)
- `projectile-compile-cmd-map' (test stub)"
(let* ((projectile-compile-cmd-map (make-hash-table :test 'equal))
- (cj/--projectile-revert-state
+ (state
(list :map 'projectile-compile-cmd-map
:root "/p/"
:prior "pytest")))
(puthash "/p/" "pytest" projectile-compile-cmd-map)
- (cj/--projectile-revert-on-fail nil "exited abnormally with code 1\n")
+ (cj/--projectile-revert-state-on-fail
+ state "exited abnormally with code 1\n")
;; Cache value still equals the prior value (unchanged through the run).
(should (string= (gethash "/p/" projectile-compile-cmd-map) "pytest"))))
-(ert-deftest test-dev-fkeys-projectile-revert-on-fail-failure-with-nil-prior-no-revert ()
+(ert-deftest test-dev-fkeys-projectile-revert-state-on-fail-failure-with-nil-prior-no-revert ()
"Boundary: failure with no prior cmd cached → don't store nil.
A nil prior means projectile cached for the first time on this run; even
if it failed, there's nothing to revert to."
(let* ((projectile-compile-cmd-map (make-hash-table :test 'equal))
- (cj/--projectile-revert-state
+ (state
(list :map 'projectile-compile-cmd-map
:root "/p/"
:prior nil)))
(puthash "/p/" "broken-cmd" projectile-compile-cmd-map)
- (cj/--projectile-revert-on-fail nil "exited abnormally\n")
+ (cj/--projectile-revert-state-on-fail state "exited abnormally\n")
(should (string= (gethash "/p/" projectile-compile-cmd-map) "broken-cmd"))))
;;; Error Cases
-(ert-deftest test-dev-fkeys-projectile-revert-on-fail-nil-state-is-noop ()
+(ert-deftest test-dev-fkeys-projectile-revert-state-on-fail-nil-state-is-noop ()
"Error: nil state (capture didn't run) → hook is a no-op, no error."
- (let ((cj/--projectile-revert-state nil))
- (cj/--projectile-revert-on-fail nil "exited abnormally\n")
- (should (null cj/--projectile-revert-state))))
+ (should-not (cj/--projectile-revert-state-on-fail
+ nil "exited abnormally\n")))
(provide 'test-dev-fkeys--projectile-revert-on-fail)
;;; test-dev-fkeys--projectile-revert-on-fail.el ends here