aboutsummaryrefslogtreecommitdiff
path: root/tests/test-prog-lisp.el
blob: ab980c5b3009b2892b88370232f6ea224da7ffe9 (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
;;; test-prog-lisp.el --- Smoke tests for prog-lisp owned config -*- lexical-binding: t; -*-

;;; Commentary:

;; prog-lisp.el is mostly use-package config; the behavior it owns directly is
;; the two mode-setup functions and their hook registration.  These tests load
;; the module with use-package stubbed to a no-op, so no packages load, ensure,
;; or download in batch, then assert the setup hooks are registered and apply
;; the buffer-local conventions this config sets.

;;; Code:

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

(defconst test-prog-lisp--repo-root
  (file-name-directory
   (directory-file-name
    (file-name-directory (or load-file-name buffer-file-name))))
  "Repository root, derived from this file's location under tests/.")

(defun test-prog-lisp--load ()
  "Load prog-lisp.el with use-package stubbed so no packages load or install."
  (cl-letf (((symbol-function 'use-package)
             (cons 'macro (lambda (&rest _) nil))))
    (load (expand-file-name "modules/prog-lisp.el" test-prog-lisp--repo-root)
          nil t)))

;;; cj/elisp-setup

(ert-deftest test-prog-lisp-elisp-setup-registered ()
  "Normal: the elisp setup function is added to emacs-lisp-mode-hook."
  (let ((emacs-lisp-mode-hook nil))
    (test-prog-lisp--load)
    (should (memq 'cj/elisp-setup emacs-lisp-mode-hook))))

(ert-deftest test-prog-lisp-elisp-setup-sets-buffer-locals ()
  "Normal: elisp setup uses 4-space indent, no tabs, fill-column 120."
  (test-prog-lisp--load)
  (with-temp-buffer
    (cl-letf (((symbol-function 'display-fill-column-indicator-mode) #'ignore))
      (cj/elisp-setup)
      (should (= tab-width 4))
      (should (null indent-tabs-mode))
      (should (= fill-column 120)))))

;;; cj/common-lisp-setup

(ert-deftest test-prog-lisp-common-lisp-setup-registered ()
  "Normal: the Common Lisp setup function is added to lisp-mode-hook."
  (let ((lisp-mode-hook nil))
    (test-prog-lisp--load)
    (should (memq 'cj/common-lisp-setup lisp-mode-hook))))

(ert-deftest test-prog-lisp-common-lisp-setup-sets-buffer-locals ()
  "Normal: Common Lisp setup uses 2-space indent, no tabs, fill-column 100."
  (test-prog-lisp--load)
  (with-temp-buffer
    (cj/common-lisp-setup)
    (should (= tab-width 2))
    (should (null indent-tabs-mode))
    (should (= fill-column 100))))

(provide 'test-prog-lisp)
;;; test-prog-lisp.el ends here