aboutsummaryrefslogtreecommitdiff
path: root/tests/test-dev-fkeys--f4-compile-and-run-impl.el
blob: d59a6cd64a193990dc2a69f87507e4091bf45195 (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
;;; 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