Commit 3eb4603b authored by Noam Postavsky's avatar Noam Postavsky

Match w32 paths in grep sans --null hits (Bug#32051)

* lisp/progmodes/grep.el (grep-regexp-alist): Add an optional part to
match paths starting with C: (other drive letters).
* test/lisp/progmodes/compile-tests.el
(compile-test-grep-regexps): New tests.
(compile--test-error-line): Return `compilation-message'.
parent 5cc7c4b4
......@@ -379,7 +379,9 @@ Notice that using \\[next-error] or \\[compile-goto-error] modifies
;; to handle weird file names (with colons in them) as
;; well as possible. E.g., use [1-9][0-9]* rather than
;; [0-9]+ so as to accept ":034:" in file names.
"\\(?1:[^\n:]+?[^\n/:]\\):[\t ]*\\(?2:[1-9][0-9]*\\)[\t ]*:"
"\\(?:[a-zA-Z]:\\)?" ; Allow "C:..." for w32.
"[^\n:]+?[^\n/:]\\):[\t ]*\\(?2:[1-9][0-9]*\\)[\t ]*:"
1 2
;; Calculate column positions (col . end-col) of first grep match on a line
......@@ -343,6 +343,29 @@ meaning a range of columns starting on LINE and ending on
END-LINE, if that matched. TYPE can be left out, in which case
any message type is accepted.")
(defconst compile-tests--grep-regexp-testcases
;; Bug#32051.
'(("c:/Users/\\src\\kbhit.hpp\0\ 29:#include <termios.h>"
1 nil 29 "c:/Users/\\src\\kbhit.hpp")
("d:/gnu/emacs/branch/src/callproc.c\0\ 214:#ifdef DOS_NT"
1 nil 214 "d:/gnu/emacs/branch/src/callproc.c")
("/gnu/emacs/branch/src/callproc.c\0\ 214:#ifdef DOS_NT"
1 nil 214 "/gnu/emacs/branch/src/callproc.c"))
"List of tests for `grep-regexp-list'.
The format is the same as `compile-tests--test-regexps-data', but
the match is expected to be the same when NUL bytes are replaced
with colon.")
(defconst compile-tests--grep-regexp-tricky-testcases
;; Bug#7378.
'(("./x11-libs---nx/3.4.0:0:C.30253.1289557929.792611.C/nx-3.4.0.exheres-0\0\ 42:some text"
1 nil 42 "./x11-libs---nx/3.4.0:0:C.30253.1289557929.792611.C/nx-3.4.0.exheres-0")
("2011-08-31_11:57:03_1\0\ 7:Date: Wed, 31 Aug 2011 11:57:03 +0000"
1 nil 7 "2011-08-31_11:57:03_1"))
"List of tricky tests for `grep-regexp-list'.
Same as `compile-tests--grep-regexp-testcases', but these cases
can only work with the NUL byte to disambiguate colons.")
(defun compile--test-error-line (test)
(setq compilation-locs (make-hash-table))
......@@ -370,7 +393,8 @@ any message type is accepted.")
(should (equal (car (nth 2 (compilation--loc->file-struct loc)))
(or end-line line)))
(when type
(should (equal type (compilation--message->type msg)))))))
(should (equal type (compilation--message->type msg)))))
(ert-deftest compile-test-error-regexps ()
"Test the `compilation-error-regexp-alist' regexps.
......@@ -379,4 +403,24 @@ The test data is in `compile-tests--test-regexps-data'."
(font-lock-mode -1)
(mapc #'compile--test-error-line compile-tests--test-regexps-data)))
(ert-deftest compile-test-grep-regexps ()
"Test the `grep-regexp-alist' regexps.
The test data is in `compile-tests--grep-regexp-testcases'."
(setq buffer-read-only nil)
(font-lock-mode -1)
(dolist (testcase compile-tests--grep-regexp-testcases)
(let (msg1 msg2)
(setq msg1 (ert-info ((format "%S" testcase) :prefix "testcase: ")
(compile--test-error-line testcase)))
;; Make sure replacing the NUL character with a colon still matches.
(setf (car testcase) (replace-regexp-in-string "\0" ":" (car testcase)))
(setq msg2 (ert-info ((format "%S" testcase) :prefix "testcase: ")
(compile--test-error-line testcase)))
(should (equal msg1 msg2))))
(dolist (testcase compile-tests--grep-regexp-tricky-testcases)
(ert-info ((format "%S" testcase) :prefix "testcase: ")
(compile--test-error-line testcase)))))
;;; compile-tests.el ends here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment