aboutsummaryrefslogtreecommitdiff
path: root/tests/test-dev-fkeys--detect-project-type.el
blob: 3b3064847cbffcf01a153ffe1b640665d93a6bc0 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
;;; test-dev-fkeys--detect-project-type.el --- Tests for cj/--detect-project-type -*- lexical-binding: t -*-

;;; Commentary:
;; Tests for the project-type classifier in dev-fkeys.el.
;; The classifier returns 'compiled, 'interpreted, or 'unknown based on
;; marker files at the project root. Interpreted markers are checked first
;; so a Python or Node project with a Makefile for tasks classifies as
;; interpreted.

;;; Code:

(require 'ert)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'dev-fkeys)

(defmacro test-dev-fkeys--with-project-dir (markers &rest body)
  "Create a temp project dir with each filename in MARKERS as an empty file.
Bind the dir path to ROOT in BODY. Cleans up on exit."
  (declare (indent 1))
  `(let ((root (make-temp-file "test-dev-fkeys-" 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-detect-project-type-go-mod-is-compiled ()
  "Normal: go.mod marker classifies as compiled."
  (test-dev-fkeys--with-project-dir '("go.mod")
    (should (eq (cj/--detect-project-type root) 'compiled))))

(ert-deftest test-dev-fkeys-detect-project-type-cargo-toml-is-compiled ()
  "Normal: Cargo.toml marker classifies as compiled."
  (test-dev-fkeys--with-project-dir '("Cargo.toml")
    (should (eq (cj/--detect-project-type root) 'compiled))))

(ert-deftest test-dev-fkeys-detect-project-type-cmakelists-is-compiled ()
  "Normal: CMakeLists.txt marker classifies as compiled."
  (test-dev-fkeys--with-project-dir '("CMakeLists.txt")
    (should (eq (cj/--detect-project-type root) 'compiled))))

(ert-deftest test-dev-fkeys-detect-project-type-makefile-is-compiled ()
  "Normal: Makefile marker classifies as compiled."
  (test-dev-fkeys--with-project-dir '("Makefile")
    (should (eq (cj/--detect-project-type root) 'compiled))))

(ert-deftest test-dev-fkeys-detect-project-type-eask-is-compiled ()
  "Normal: Eask marker classifies as compiled."
  (test-dev-fkeys--with-project-dir '("Eask")
    (should (eq (cj/--detect-project-type root) 'compiled))))

(ert-deftest test-dev-fkeys-detect-project-type-pyproject-is-interpreted ()
  "Normal: pyproject.toml marker classifies as interpreted."
  (test-dev-fkeys--with-project-dir '("pyproject.toml")
    (should (eq (cj/--detect-project-type root) 'interpreted))))

(ert-deftest test-dev-fkeys-detect-project-type-requirements-is-interpreted ()
  "Normal: requirements.txt marker classifies as interpreted."
  (test-dev-fkeys--with-project-dir '("requirements.txt")
    (should (eq (cj/--detect-project-type root) 'interpreted))))

(ert-deftest test-dev-fkeys-detect-project-type-pipfile-is-interpreted ()
  "Normal: Pipfile marker classifies as interpreted."
  (test-dev-fkeys--with-project-dir '("Pipfile")
    (should (eq (cj/--detect-project-type root) 'interpreted))))

(ert-deftest test-dev-fkeys-detect-project-type-package-json-is-interpreted ()
  "Normal: package.json marker classifies as interpreted."
  (test-dev-fkeys--with-project-dir '("package.json")
    (should (eq (cj/--detect-project-type root) 'interpreted))))

;;; Boundary Cases

(ert-deftest test-dev-fkeys-detect-project-type-interpreted-wins-over-compiled ()
  "Boundary: a Python project with a Makefile classifies as interpreted.
Interpreted markers are checked first so task-runner Makefiles in
Python/Node projects don't misclassify them as compiled."
  (test-dev-fkeys--with-project-dir '("pyproject.toml" "Makefile")
    (should (eq (cj/--detect-project-type root) 'interpreted))))

(ert-deftest test-dev-fkeys-detect-project-type-package-json-wins-over-makefile ()
  "Boundary: package.json + Makefile classifies as interpreted."
  (test-dev-fkeys--with-project-dir '("package.json" "Makefile")
    (should (eq (cj/--detect-project-type root) 'interpreted))))

(ert-deftest test-dev-fkeys-detect-project-type-pure-c-with-makefile-is-compiled ()
  "Boundary: a Makefile alone (no interpreted markers) classifies as compiled.
This is the typical pure-C project case."
  (test-dev-fkeys--with-project-dir '("Makefile")
    (should (eq (cj/--detect-project-type root) 'compiled))))

(ert-deftest test-dev-fkeys-detect-project-type-no-markers-is-unknown ()
  "Boundary: directory with no markers classifies as unknown."
  (test-dev-fkeys--with-project-dir '()
    (should (eq (cj/--detect-project-type root) 'unknown))))

(ert-deftest test-dev-fkeys-detect-project-type-irrelevant-file-is-unknown ()
  "Boundary: unrelated files in root don't trigger any classification."
  (test-dev-fkeys--with-project-dir '("README.md" "LICENSE" ".gitignore")
    (should (eq (cj/--detect-project-type root) 'unknown))))

;;; Error Cases

(ert-deftest test-dev-fkeys-detect-project-type-nil-root-is-unknown ()
  "Error: nil ROOT returns 'unknown (buffer not in a project)."
  (should (eq (cj/--detect-project-type nil) 'unknown)))

(ert-deftest test-dev-fkeys-detect-project-type-nonexistent-root-is-unknown ()
  "Error: a directory path that doesn't exist returns 'unknown.
file-exists-p on a non-existent path returns nil, so no marker matches."
  (should (eq (cj/--detect-project-type "/nonexistent/path/xyzzy") 'unknown)))

(provide 'test-dev-fkeys--detect-project-type)
;;; test-dev-fkeys--detect-project-type.el ends here