blob: 78e4c81518f0b00cecbb92367e08998eaf1ef217 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
;;; test-dev-fkeys--projectile-revert-on-fail.el --- Tests for projectile revert decisions -*- lexical-binding: t -*-
;;; Commentary:
;; 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:
(require 'ert)
(require 'cl-lib)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'dev-fkeys)
(defvar projectile-compile-cmd-map nil)
;;; Normal Cases
(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))
(state
(list :map 'projectile-compile-cmd-map
:root "/p/"
:prior "make build")))
(puthash "/p/" "make buidl" projectile-compile-cmd-map)
(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-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))
(state
(list :map 'projectile-compile-cmd-map
:root "/p/"
:prior "make build")))
(puthash "/p/" "make build-fast" projectile-compile-cmd-map)
(cj/--projectile-revert-state-on-fail state "finished\n")
(should (string= (gethash "/p/" projectile-compile-cmd-map) "make build-fast"))))
;;; Boundary Cases
(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-state-on-fail' (unit under test)
- `projectile-compile-cmd-map' (test stub)"
(let* ((projectile-compile-cmd-map (make-hash-table :test 'equal))
(state
(list :map 'projectile-compile-cmd-map
:root "/p/"
:prior "pytest")))
(puthash "/p/" "pytest" projectile-compile-cmd-map)
(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-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))
(state
(list :map 'projectile-compile-cmd-map
:root "/p/"
:prior nil)))
(puthash "/p/" "broken-cmd" projectile-compile-cmd-map)
(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-state-on-fail-nil-state-is-noop ()
"Error: nil state (capture didn't run) → hook is a no-op, no error."
(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
|