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

;;; Commentary:
;; Go's binding is installed via `local-set-key' inside the
;; `cj/go-mode-keybindings' hook, not via use-package's `:bind'. The
;; test runs the hook directly in a temp buffer and asks the buffer-
;; local map what C-; f resolves to.
;;
;; Three checks:
;;   1. `gofmt' is fboundp after go-mode loads.
;;   2. The hook installs C-; f → `gofmt' in the buffer-local map.
;;   3. `gofmt' (or `goimports') is on PATH.

;;; Code:

(require 'ert)

(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)
(require 'prog-go)
(require 'go-mode)

(ert-deftest test-prog-go-format-package-loaded ()
  "Normal: `go-mode' is in `features' after the prog-go config loads."
  (should (featurep 'go-mode)))

(ert-deftest test-prog-go-format-command-fboundp ()
  "Normal: `gofmt' is fboundp after `go-mode' loads."
  (should (fboundp 'gofmt)))

(ert-deftest test-prog-go-format-binding-resolves ()
  "Normal: `cj/go-mode-keybindings' installs C-; f → `gofmt' locally."
  (with-temp-buffer
    (cj/go-mode-keybindings)
    (should (eq 'gofmt (local-key-binding (kbd "C-; f"))))))

(ert-deftest test-prog-go-format-executable-on-path ()
  "Boundary: `gofmt' or `goimports' is on PATH (skipped if neither installed).
The Go config sets `gofmt-command' to \"goimports\" but falls back to
plain `gofmt' if goimports isn't installed."
  (unless (or (executable-find "gofmt") (executable-find "goimports"))
    (ert-skip "Neither gofmt nor goimports on PATH"))
  (should (or (executable-find "gofmt")
              (executable-find "goimports"))))

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