aboutsummaryrefslogtreecommitdiff
path: root/tests/test-dev-fkeys--f4-compile-only.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-dev-fkeys--f4-compile-only.el')
-rw-r--r--tests/test-dev-fkeys--f4-compile-only.el61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test-dev-fkeys--f4-compile-only.el b/tests/test-dev-fkeys--f4-compile-only.el
new file mode 100644
index 00000000..b0eec367
--- /dev/null
+++ b/tests/test-dev-fkeys--f4-compile-only.el
@@ -0,0 +1,61 @@
+;;; 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-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