Debian Codegraph @

contrib/hg-test-mode.el

raw
1 ;; hg-test-mode.el - Major mode for editing Mercurial tests
2 ;;
3 ;; Copyright 2014 Olivia Mackall <[email protected]>
4 ;; "I have no idea what I'm doing"
5 ;;
6 ;; This software may be used and distributed according to the terms of the
7 ;; GNU General Public License version 2 or any later version.
8 ;;
9 ;; To enable, add something like the following to your .emacs:
10 ;;
11 ;; (if (file-exists-p "~/hg/contrib/hg-test-mode.el")
12 ;; (load "~/hg/contrib/hg-test-mode.el"))
13
14 (defvar hg-test-mode-hook nil)
15
16 (defvar hg-test-mode-map
17 (let ((map (make-keymap)))
18 (define-key map "\C-j" 'newline-and-indent)
19 map)
20 "Keymap for hg test major mode")
21
22 (add-to-list 'auto-mode-alist '("\\.t\\'" . hg-test-mode))
23
24 (defconst hg-test-font-lock-keywords-1
25 (list
26 '("^ \\(\\$\\|>>>\\) " 1 font-lock-builtin-face)
27 '("^ \\(>\\|\\.\\.\\.\\) " 1 font-lock-constant-face)
28 '("^ \\([[][0-9]+[]]\\)$" 1 font-lock-warning-face)
29 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)*\\)$" 1 font-lock-string-face)
30 '("\\$?\\(HG\\|TEST\\)\\w+=?" . font-lock-variable-name-face)
31 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)+\\)$" 2 font-lock-type-face)
32 '("^#.*" . font-lock-preprocessor-face)
33 '("^\\([^ ].*\\)$" 1 font-lock-comment-face)
34 )
35 "Minimal highlighting expressions for hg-test mode")
36
37 (defvar hg-test-font-lock-keywords hg-test-font-lock-keywords-1
38 "Default highlighting expressions for hg-test mode")
39
40 (defvar hg-test-mode-syntax-table
41 (let ((st (make-syntax-table)))
42 (modify-syntax-entry ?\" "w" st) ;; disable standard quoting
43 st)
44 "Syntax table for hg-test mode")
45
46 (defun hg-test-mode ()
47 (interactive)
48 (kill-all-local-variables)
49 (use-local-map hg-test-mode-map)
50 (set-syntax-table hg-test-mode-syntax-table)
51 (set (make-local-variable 'font-lock-defaults) '(hg-test-font-lock-keywords))
52 (setq major-mode 'hg-test-mode)
53 (setq mode-name "hg-test")
54 (run-hooks 'hg-test-mode-hook))
55
56 (with-eval-after-load "compile"
57 ;; Link to Python sources in tracebacks in .t failures.
58 (add-to-list 'compilation-error-regexp-alist-alist
59 '(hg-test-output-python-tb
60 "^\\+ +File ['\"]\\([^'\"]+\\)['\"], line \\([0-9]+\\)," 1 2))
61 (add-to-list 'compilation-error-regexp-alist 'hg-test-output-python-tb)
62 ;; Link to source files in test-check-code.t violations.
63 (add-to-list 'compilation-error-regexp-alist-alist
64 '(hg-test-check-code-output
65 "\\+ \\([^:\n]+\\):\\([0-9]+\\):$" 1 2))
66 (add-to-list 'compilation-error-regexp-alist 'hg-test-check-code-output))
67
68 (defun hg-test-mode--test-one-error-line-regexp (test)
69 (erase-buffer)
70 (setq compilation-locs (make-hash-table))
71 (insert (car test))
72 (compilation-parse-errors (point-min) (point-max))
73 (let ((msg (get-text-property 1 'compilation-message)))
74 (should msg)
75 (let ((loc (compilation--message->loc msg))
76 (line (nth 1 test))
77 (file (nth 2 test)))
78 (should (equal (compilation--loc->line loc) line))
79 (should (equal (caar (compilation--loc->file-struct loc)) file)))
80 msg))
81
82 (require 'ert)
83 (ert-deftest hg-test-mode--compilation-mode-support ()
84 "Test hg-specific compilation-mode regular expressions"
85 (require 'compile)
86 (with-temp-buffer
87 (font-lock-mode -1)
88 (mapc 'hg-test-mode--test-one-error-line-regexp
89 '(
90 ("+ contrib/debugshell.py:37:" 37 "contrib/debugshell.py")
91 ("+ File \"/tmp/hg/mercurial/commands.py\", line 3115, in help_"
92 3115 "/tmp/hg/mercurial/commands.py")
93 ("+ File \"mercurial/dispatch.py\", line 225, in dispatch"
94 225 "mercurial/dispatch.py")))))
95
96
97 (provide 'hg-test-mode)