Mercurial > dotfiles
comparison .elisp/settings/50.compilation-tweaks.el @ 478:6bcdbe7b8e42
emacs: fix up hg test output regular expressions
Includes some unit tests cribbed from compilation-mode's own tests.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Wed, 20 Feb 2019 16:27:47 -0500 |
parents | b0264224e2ec |
children |
comparison
equal
deleted
inserted
replaced
477:8373f6924e50 | 478:6bcdbe7b8e42 |
---|---|
1 (require 'compile) | 1 (require 'compile) |
2 | 2 |
3 (setq af--hg-test-traceback | 3 (setq af--hg-test-traceback "^\\+ File ['\"]\\([^'\"]+\\)['\"], line \\([0-9]+\\),") |
4 (rx | |
5 bol | |
6 "+ File \"" | |
7 (one-or-more not-newline) | |
8 "/install/lib/python/" | |
9 (group (one-or-more (not (any "\"")))) | |
10 ", line " | |
11 (group (one-or-more digit)) | |
12 ) | |
13 ) | |
14 | 4 |
15 (setq compilation-error-regexp-alist-alist | 5 (setq compilation-error-regexp-alist-alist |
16 (cons '(mercurial-test-output-tb af--hg-test-traceback 1 2) | 6 (cons `(mercurial-test-output-tb ,af--hg-test-traceback 1 2) |
17 (assq-delete-all 'mercurial-test-output-tb | 7 (assq-delete-all 'mercurial-test-output-tb |
18 compilation-error-regexp-alist-alist))) | 8 compilation-error-regexp-alist-alist))) |
19 | 9 |
20 (setq af--hg-check-code-error-re | 10 (setq af--hg-check-code-error-re " \\([^:\n]+\\):\\([0-9]+\\):$") |
21 (rx | |
22 bol | |
23 "+ " | |
24 (group (one-or-more not-newline)) | |
25 ":" | |
26 (group (one-or-more digit)) | |
27 ":" | |
28 ) | |
29 ) | |
30 | 11 |
31 (setq compilation-error-regexp-alist-alist | 12 (setq compilation-error-regexp-alist-alist |
32 (cons '(mercurial-check-code-output af--hg-check-code-error-re 1 2) | 13 (cons `(mercurial-check-code-output ,af--hg-check-code-error-re 1 2) |
33 (assq-delete-all 'mercurial-check-code-output | 14 (assq-delete-all 'mercurial-check-code-output |
34 compilation-error-regexp-alist-alist))) | 15 compilation-error-regexp-alist-alist))) |
35 | 16 |
36 (add-to-list 'compilation-error-regexp-alist 'mercurial-test-output-tb) | 17 (add-to-list 'compilation-error-regexp-alist 'mercurial-test-output-tb) |
37 (add-to-list 'compilation-error-regexp-alist 'mercurial-check-code-output) | 18 (add-to-list 'compilation-error-regexp-alist 'mercurial-check-code-output) |
38 | 19 |
39 ;; to debug: | 20 ;; to debug: |
40 ;;(setq compilation-error-regexp-alist '(mercurial-check-code-output)) | 21 ;;(setq compilation-error-regexp-alist '(mercurial-check-code-output |
22 ;; mercurial-test-output-tb)) | |
23 | |
24 | |
25 ;; stolen from compile-tests.el | |
26 (defun af--compile--test-error-line (test) | |
27 (erase-buffer) | |
28 (setq compilation-locs (make-hash-table)) | |
29 (insert (car test)) | |
30 (compilation-parse-errors (point-min) (point-max)) | |
31 (let ((msg (get-text-property (nth 1 test) 'compilation-message))) | |
32 (should msg) | |
33 (let ((loc (compilation--message->loc msg)) | |
34 (col (nth 2 test)) | |
35 (line (nth 3 test)) | |
36 (file (nth 4 test)) | |
37 (type (nth 5 test)) | |
38 end-col end-line) | |
39 (if (consp col) | |
40 (setq end-col (cdr col) col (car col))) | |
41 (if (consp line) | |
42 (setq end-line (cdr line) line (car line))) | |
43 (should (equal (compilation--loc->col loc) col)) | |
44 (should (equal (compilation--loc->line loc) line)) | |
45 (when file | |
46 (should (equal (caar (compilation--loc->file-struct loc)) file))) | |
47 (when end-col | |
48 (should (equal (car (cadr (nth 2 (compilation--loc->file-struct loc)))) | |
49 end-col))) | |
50 (should (equal (car (nth 2 (compilation--loc->file-struct loc))) | |
51 (or end-line line))) | |
52 (when type | |
53 (should (equal type (compilation--message->type msg))))) | |
54 msg)) | |
55 | |
56 (defvar af--compile-tests--test-regexps-data | |
57 ;; The computed column numbers are zero-indexed, so subtract 1 from | |
58 ;; what's reported in the string. The end column numbers are for | |
59 ;; the character after, so it matches what's reported in the string. | |
60 '(;;hg test-check-code | |
61 ("+ contrib/debugshell.py:37:" 1 nil 37 "contrib/debugshell.py") | |
62 ("+ File \"/tmp/hg/mercurial/commands.py\", line 3115, in help_" | |
63 1 nil 3115 "/tmp/hg/mercurial/commands.py") | |
64 )) | |
65 | |
66 (require 'ert) | |
67 (ert-deftest af--hg-error-cases () | |
68 "Test hg-specific compilation-mode regular expressions" | |
69 (with-temp-buffer | |
70 (font-lock-mode -1) | |
71 (mapc #'af--compile--test-error-line af--compile-tests--test-regexps-data))) | |
72 | |
73 ;; To run tests: | |
74 ;; | |
75 ;; emacs -batch -l .elisp/settings/50.compilation-tweaks.el -f ert-run-tests-batch-and-exit |