##// END OF EJS Templates
tests: add test for hg-test-mode emacs code...
Augie Fackler -
r41954:19979b8b default
parent child Browse files
Show More
@@ -0,0 +1,8 b''
1 #require emacs
2 $ emacs -q -no-site-file -batch -l $TESTDIR/../contrib/hg-test-mode.el \
3 > -f ert-run-tests-batch-and-exit
4 Running 1 tests (*) (glob)
5 passed 1/1 hg-test-mode--compilation-mode-support
6
7 Ran 1 tests, 1 results as expected (*) (glob)
8
@@ -1,68 +1,97 b''
1 ;; hg-test-mode.el - Major mode for editing Mercurial tests
1 ;; hg-test-mode.el - Major mode for editing Mercurial tests
2 ;;
2 ;;
3 ;; Copyright 2014 Matt Mackall <mpm@selenic.com>
3 ;; Copyright 2014 Matt Mackall <mpm@selenic.com>
4 ;; "I have no idea what I'm doing"
4 ;; "I have no idea what I'm doing"
5 ;;
5 ;;
6 ;; This software may be used and distributed according to the terms of the
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.
7 ;; GNU General Public License version 2 or any later version.
8 ;;
8 ;;
9 ;; To enable, add something like the following to your .emacs:
9 ;; To enable, add something like the following to your .emacs:
10 ;;
10 ;;
11 ;; (if (file-exists-p "~/hg/contrib/hg-test-mode.el")
11 ;; (if (file-exists-p "~/hg/contrib/hg-test-mode.el")
12 ;; (load "~/hg/contrib/hg-test-mode.el"))
12 ;; (load "~/hg/contrib/hg-test-mode.el"))
13
13
14 (defvar hg-test-mode-hook nil)
14 (defvar hg-test-mode-hook nil)
15
15
16 (defvar hg-test-mode-map
16 (defvar hg-test-mode-map
17 (let ((map (make-keymap)))
17 (let ((map (make-keymap)))
18 (define-key map "\C-j" 'newline-and-indent)
18 (define-key map "\C-j" 'newline-and-indent)
19 map)
19 map)
20 "Keymap for hg test major mode")
20 "Keymap for hg test major mode")
21
21
22 (add-to-list 'auto-mode-alist '("\\.t\\'" . hg-test-mode))
22 (add-to-list 'auto-mode-alist '("\\.t\\'" . hg-test-mode))
23
23
24 (defconst hg-test-font-lock-keywords-1
24 (defconst hg-test-font-lock-keywords-1
25 (list
25 (list
26 '("^ \\(\\$\\|>>>\\) " 1 font-lock-builtin-face)
26 '("^ \\(\\$\\|>>>\\) " 1 font-lock-builtin-face)
27 '("^ \\(>\\|\\.\\.\\.\\) " 1 font-lock-constant-face)
27 '("^ \\(>\\|\\.\\.\\.\\) " 1 font-lock-constant-face)
28 '("^ \\([[][0-9]+[]]\\)$" 1 font-lock-warning-face)
28 '("^ \\([[][0-9]+[]]\\)$" 1 font-lock-warning-face)
29 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)*\\)$" 1 font-lock-string-face)
29 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)*\\)$" 1 font-lock-string-face)
30 '("\\$?\\(HG\\|TEST\\)\\w+=?" . font-lock-variable-name-face)
30 '("\\$?\\(HG\\|TEST\\)\\w+=?" . font-lock-variable-name-face)
31 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)+\\)$" 2 font-lock-type-face)
31 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)+\\)$" 2 font-lock-type-face)
32 '("^#.*" . font-lock-preprocessor-face)
32 '("^#.*" . font-lock-preprocessor-face)
33 '("^\\([^ ].*\\)$" 1 font-lock-comment-face)
33 '("^\\([^ ].*\\)$" 1 font-lock-comment-face)
34 )
34 )
35 "Minimal highlighting expressions for hg-test mode")
35 "Minimal highlighting expressions for hg-test mode")
36
36
37 (defvar hg-test-font-lock-keywords hg-test-font-lock-keywords-1
37 (defvar hg-test-font-lock-keywords hg-test-font-lock-keywords-1
38 "Default highlighting expressions for hg-test mode")
38 "Default highlighting expressions for hg-test mode")
39
39
40 (defvar hg-test-mode-syntax-table
40 (defvar hg-test-mode-syntax-table
41 (let ((st (make-syntax-table)))
41 (let ((st (make-syntax-table)))
42 (modify-syntax-entry ?\" "w" st) ;; disable standard quoting
42 (modify-syntax-entry ?\" "w" st) ;; disable standard quoting
43 st)
43 st)
44 "Syntax table for hg-test mode")
44 "Syntax table for hg-test mode")
45
45
46 (defun hg-test-mode ()
46 (defun hg-test-mode ()
47 (interactive)
47 (interactive)
48 (kill-all-local-variables)
48 (kill-all-local-variables)
49 (use-local-map hg-test-mode-map)
49 (use-local-map hg-test-mode-map)
50 (set-syntax-table hg-test-mode-syntax-table)
50 (set-syntax-table hg-test-mode-syntax-table)
51 (set (make-local-variable 'font-lock-defaults) '(hg-test-font-lock-keywords))
51 (set (make-local-variable 'font-lock-defaults) '(hg-test-font-lock-keywords))
52 (setq major-mode 'hg-test-mode)
52 (setq major-mode 'hg-test-mode)
53 (setq mode-name "hg-test")
53 (setq mode-name "hg-test")
54 (run-hooks 'hg-test-mode-hook))
54 (run-hooks 'hg-test-mode-hook))
55
55
56 (with-eval-after-load "compile"
56 (with-eval-after-load "compile"
57 ;; Link to Python sources in tracebacks in .t failures.
57 ;; Link to Python sources in tracebacks in .t failures.
58 (add-to-list 'compilation-error-regexp-alist-alist
58 (add-to-list 'compilation-error-regexp-alist-alist
59 '(hg-test-output-python-tb
59 '(hg-test-output-python-tb
60 "^\\+ +File ['\"]\\([^'\"]+\\)['\"], line \\([0-9]+\\)," 1 2))
60 "^\\+ +File ['\"]\\([^'\"]+\\)['\"], line \\([0-9]+\\)," 1 2))
61 (add-to-list 'compilation-error-regexp-alist 'hg-test-output-python-tb)
61 (add-to-list 'compilation-error-regexp-alist 'hg-test-output-python-tb)
62 ;; Link to source files in test-check-code.t violations.
62 ;; Link to source files in test-check-code.t violations.
63 (add-to-list 'compilation-error-regexp-alist-alist
63 (add-to-list 'compilation-error-regexp-alist-alist
64 '(hg-test-check-code-output
64 '(hg-test-check-code-output
65 "\\+ \\([^:\n]+\\):\\([0-9]+\\):$" 1 2))
65 "\\+ \\([^:\n]+\\):\\([0-9]+\\):$" 1 2))
66 (add-to-list 'compilation-error-regexp-alist 'hg-test-check-code-output))
66 (add-to-list 'compilation-error-regexp-alist 'hg-test-check-code-output))
67
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
68 (provide 'hg-test-mode)
97 (provide 'hg-test-mode)
General Comments 0
You need to be logged in to leave comments. Login now