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