aboutsummaryrefslogtreecommitdiff
path: root/tests/test-dev-fkeys--f4-compile-only.el
blob: 815aa09770f8dc72d8cdcee48c626e521df42f4f (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
;;; 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-propagates-prefix-arg ()
  "Normal: on a compiled project, `current-prefix-arg' is forwarded to
projectile-compile-project so `C-u C-F4' forces a re-prompt."
  (test-dev-fkeys-co--with-project '("go.mod")
    (let ((seen-arg 'unset)
          (current-prefix-arg t))
      (cl-letf (((symbol-function 'cj/--f4-project-root) (lambda () root))
                ((symbol-function 'projectile-compile-project)
                 (lambda (arg) (setq seen-arg arg))))
        (cj/f4-compile-only)
        (should (eq seen-arg t))))))

(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