changeset 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 8373f6924e50
children 601884c45f8a
files .elisp/settings/50.compilation-tweaks.el
diffstat 1 files changed, 59 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/.elisp/settings/50.compilation-tweaks.el
+++ b/.elisp/settings/50.compilation-tweaks.el
@@ -1,35 +1,16 @@
 (require 'compile)
 
-(setq af--hg-test-traceback
-      (rx
-       bol
-       "+  File \""
-       (one-or-more not-newline)
-       "/install/lib/python/"
-       (group (one-or-more (not (any "\""))))
-       ", line "
-       (group (one-or-more digit))
-       )
-      )
+(setq af--hg-test-traceback "^\\+  File ['\"]\\([^'\"]+\\)['\"], line \\([0-9]+\\),")
 
 (setq compilation-error-regexp-alist-alist
-  (cons '(mercurial-test-output-tb af--hg-test-traceback 1 2)
+  (cons `(mercurial-test-output-tb ,af--hg-test-traceback 1 2)
         (assq-delete-all 'mercurial-test-output-tb
                          compilation-error-regexp-alist-alist)))
 
-(setq af--hg-check-code-error-re
-      (rx
-       bol
-       "+  "
-       (group (one-or-more not-newline))
-       ":"
-       (group (one-or-more digit))
-       ":"
-       )
-      )
+(setq af--hg-check-code-error-re "  \\([^:\n]+\\):\\([0-9]+\\):$")
 
 (setq compilation-error-regexp-alist-alist
-  (cons '(mercurial-check-code-output af--hg-check-code-error-re 1 2)
+  (cons `(mercurial-check-code-output ,af--hg-check-code-error-re 1 2)
         (assq-delete-all 'mercurial-check-code-output
                           compilation-error-regexp-alist-alist)))
 
@@ -37,4 +18,58 @@
 (add-to-list 'compilation-error-regexp-alist 'mercurial-check-code-output)
 
 ;; to debug:
-;;(setq compilation-error-regexp-alist '(mercurial-check-code-output))
+;;(setq compilation-error-regexp-alist '(mercurial-check-code-output
+;;                                       mercurial-test-output-tb))
+
+
+;; stolen from compile-tests.el
+(defun af--compile--test-error-line (test)
+  (erase-buffer)
+  (setq compilation-locs (make-hash-table))
+  (insert (car test))
+  (compilation-parse-errors (point-min) (point-max))
+  (let ((msg (get-text-property (nth 1 test) 'compilation-message)))
+    (should msg)
+    (let ((loc (compilation--message->loc msg))
+          (col  (nth 2 test))
+          (line (nth 3 test))
+          (file (nth 4 test))
+          (type (nth 5 test))
+          end-col end-line)
+      (if (consp col)
+          (setq end-col (cdr col) col (car col)))
+      (if (consp line)
+          (setq end-line (cdr line) line (car line)))
+      (should (equal (compilation--loc->col loc) col))
+      (should (equal (compilation--loc->line loc) line))
+      (when file
+        (should (equal (caar (compilation--loc->file-struct loc)) file)))
+      (when end-col
+        (should (equal (car (cadr (nth 2 (compilation--loc->file-struct loc))))
+                       end-col)))
+      (should (equal (car (nth 2 (compilation--loc->file-struct loc)))
+                     (or end-line line)))
+      (when type
+        (should (equal type (compilation--message->type msg)))))
+    msg))
+
+(defvar af--compile-tests--test-regexps-data
+  ;; The computed column numbers are zero-indexed, so subtract 1 from
+  ;; what's reported in the string.  The end column numbers are for
+  ;; the character after, so it matches what's reported in the string.
+  '(;;hg test-check-code
+    ("+  contrib/debugshell.py:37:" 1 nil 37 "contrib/debugshell.py")
+    ("+    File \"/tmp/hg/mercurial/commands.py\", line 3115, in help_"
+     1 nil 3115 "/tmp/hg/mercurial/commands.py")
+    ))
+
+(require 'ert)
+(ert-deftest af--hg-error-cases ()
+  "Test hg-specific compilation-mode regular expressions"
+  (with-temp-buffer
+    (font-lock-mode -1)
+    (mapc #'af--compile--test-error-line af--compile-tests--test-regexps-data)))
+
+;; To run tests:
+;;
+;; emacs -batch -l .elisp/settings/50.compilation-tweaks.el -f ert-run-tests-batch-and-exit