aboutsummaryrefslogtreecommitdiff
path: root/tests/test-prog-shell--format-wiring.el
blob: 604a1f26cb94beda46d6d995dc8cbf1cd4222710 (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
;;; test-prog-shell--format-wiring.el --- Verify the Shell formatter is wired -*- lexical-binding: t; -*-

;;; Commentary:
;; The shfmt use-package gates on `:if (executable-find shfmt-path)' so
;; the keymap entries only install when shfmt is on PATH. The bind/
;; fboundp tests therefore call the executable-skip helper first.
;;
;; Three checks for the shell formatter, each repeated for the two
;; relevant mode-maps (`sh-mode-map' and `bash-ts-mode-map'):
;;   1. `shfmt-buffer' is fboundp.
;;   2. C-; f in each map resolves to `shfmt-buffer'.
;;   3. The `shfmt' executable is on PATH.

;;; Code:

(require 'ert)
(require 'sh-script)  ; provides sh-mode-map

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory))
(require 'testutil-format-wiring)

(format-test--ensure-packages-init)
;; bash-ts-mode is autoloaded from sh-script in modern Emacs; force
;; the map into existence by referencing the mode definition.  When
;; tree-sitter isn't built in, bash-ts-mode is still defined as a
;; symbol via define-derived-mode, and its keymap exists.
(require 'prog-shell)
(when (executable-find "shfmt")
  (require 'shfmt))

(ert-deftest test-prog-shell-format-package-loaded ()
  "Normal: `shfmt' is in `features' when the executable is on PATH.
Skipped when shfmt isn't installed because the use-package gates on
`:if (executable-find shfmt-path)' and never loads the package."
  (format-test--skip-unless-executable "shfmt")
  (should (featurep 'shfmt)))

(ert-deftest test-prog-shell-format-command-fboundp ()
  "Normal: `shfmt-buffer' is fboundp after shfmt loads.
Skipped when shfmt isn't installed because the use-package gates on
`:if (executable-find shfmt-path)'."
  (format-test--skip-unless-executable "shfmt")
  (should (fboundp 'shfmt-buffer)))

(ert-deftest test-prog-shell-format-binding-in-sh-mode ()
  "Normal: C-; f in `sh-mode-map' is bound to `shfmt-buffer'."
  (format-test--skip-unless-executable "shfmt")
  (should (eq 'shfmt-buffer
              (lookup-key sh-mode-map (kbd "C-; f")))))

(ert-deftest test-prog-shell-format-binding-in-bash-ts-mode ()
  "Normal: C-; f in `bash-ts-mode-map' is bound to `shfmt-buffer'."
  (format-test--skip-unless-executable "shfmt")
  (should (boundp 'bash-ts-mode-map))
  (should (eq 'shfmt-buffer
              (lookup-key bash-ts-mode-map (kbd "C-; f")))))

(ert-deftest test-prog-shell-format-executable-on-path ()
  "Boundary: the `shfmt' executable is on PATH (skipped if not installed)."
  (format-test--skip-unless-executable "shfmt")
  (should (executable-find "shfmt")))

(provide 'test-prog-shell--format-wiring)
;;; test-prog-shell--format-wiring.el ends here