blob: eb9cec5effd8d926cff5c70d66ef5826e5af7f06 (
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
84
85
86
87
88
89
90
91
|
;;; test-dev-fkeys--f6-test-runner.el --- Smoke tests for cj/f6-test-runner -*- lexical-binding: t -*-
;;; Commentary:
;; Smoke tests for the F6 top-level menu. The wrapper:
;;
;; 1. Prompts via completing-read with two candidates.
;; 2. \"All tests\" invokes `projectile-test-project'.
;; 3. \"Current file's tests\" invokes `cj/--f6-current-file-tests-impl'
;; with the buffer's file and the project root.
;;
;; The orchestrator and helpers are tested in their own files; this file
;; just confirms the wiring.
;;; 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-f6-test-runner-prompts-with-completing-read ()
"Normal: F6 prompts with the two-entry candidate list."
(let (seen-candidates)
(cl-letf (((symbol-function 'completing-read)
(lambda (_prompt collection &rest _)
(setq seen-candidates collection)
(car collection)))
((symbol-function 'projectile-test-project)
(lambda (_arg) nil))
((symbol-function 'cj/--f4-project-root) (lambda () "/p/"))
((symbol-function 'cj/--f6-current-file-tests-impl)
(lambda (_f _r) nil)))
(cj/f6-test-runner)
(should (member "All tests" seen-candidates))
(should (member "Current file's tests" seen-candidates)))))
(ert-deftest test-dev-fkeys-f6-test-runner-all-tests-routes-to-projectile ()
"Normal: choosing 'All tests' invokes projectile-test-project."
(let ((calls 0))
(cl-letf (((symbol-function 'completing-read)
(lambda (&rest _) "All tests"))
((symbol-function 'projectile-test-project)
(lambda (_arg) (cl-incf calls)))
((symbol-function 'cj/--f4-project-root) (lambda () "/p/"))
((symbol-function 'cj/--f6-current-file-tests-impl)
(lambda (_f _r) nil)))
(cj/f6-test-runner)
(should (= calls 1)))))
(ert-deftest test-dev-fkeys-f6-test-runner-all-tests-propagates-prefix-arg ()
"Normal: choosing 'All tests' forwards `current-prefix-arg' to
projectile-test-project so `C-u F6 → All tests' forces a re-prompt."
(let ((seen-arg 'unset)
(current-prefix-arg t))
(cl-letf (((symbol-function 'completing-read)
(lambda (&rest _) "All tests"))
((symbol-function 'projectile-test-project)
(lambda (arg) (setq seen-arg arg)))
((symbol-function 'cj/--f4-project-root) (lambda () "/p/"))
((symbol-function 'cj/--f6-current-file-tests-impl)
(lambda (_f _r) nil)))
(cj/f6-test-runner)
(should (eq seen-arg t)))))
(ert-deftest test-dev-fkeys-f6-test-runner-current-file-routes-to-impl ()
"Normal: choosing 'Current file's tests' invokes the orchestrator with
the buffer file and projectile root.
Components integrated:
- `cj/f6-test-runner' (unit under test)
- `completing-read' (MOCKED — picks the second label)
- `cj/--f4-project-root' (MOCKED — fixed root)
- `cj/--f6-current-file-tests-impl' (MOCKED — captures args)
- `buffer-file-name' (MOCKED via cl-letf)"
(let (seen-file seen-root)
(cl-letf (((symbol-function 'completing-read)
(lambda (&rest _) "Current file's tests"))
((symbol-function 'projectile-test-project) (lambda (_arg) nil))
((symbol-function 'cj/--f4-project-root) (lambda () "/p/"))
((symbol-function 'buffer-file-name) (lambda () "/p/foo.el"))
((symbol-function 'cj/--f6-current-file-tests-impl)
(lambda (file root)
(setq seen-file file seen-root root))))
(cj/f6-test-runner)
(should (string= seen-file "/p/foo.el"))
(should (string= seen-root "/p/")))))
(provide 'test-dev-fkeys--f6-test-runner)
;;; test-dev-fkeys--f6-test-runner.el ends here
|