Skip to content

Commit 4bbd739

Browse files
committed
Fix ‘go-test’ compilation message pattern.
Fixes #361, #362 Restrict the prefix and filename pattern (Bug #361), and also allow for a test name prefix (Bug #362). Add regression tests for these bugs.
1 parent 734d523 commit 4bbd739

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

go-mode.el

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,8 +1841,16 @@ with goflymake (see URL `https://github.com/dougm/goflymake'), gocode
18411841
(when (and (boundp 'compilation-error-regexp-alist)
18421842
(boundp 'compilation-error-regexp-alist-alist))
18431843
(add-to-list 'compilation-error-regexp-alist 'go-test)
1844-
(add-to-list 'compilation-error-regexp-alist-alist
1845-
'(go-test . ("^\\s-+\\([^()\t\n]+\\):\\([0-9]+\\):? .*$" 1 2)) t)))
1844+
(add-to-list
1845+
'compilation-error-regexp-alist-alist
1846+
`(go-test . (,(concat "^[ \t]+" ; prefix
1847+
;; Optional test name (for go test -v):
1848+
"\\(?:[./_[:alpha:]][-./_+%@[:alnum:]]*: \\)?"
1849+
"\\([./_[:alpha:]][-./_+%@[:alnum:]]*\\):" ; file
1850+
"\\([0-9]+\\):?" ; line
1851+
" .*$")
1852+
1 2))
1853+
t)))
18461854

18471855
;;;###autoload
18481856
(add-to-list 'auto-mode-alist (cons "\\.go\\'" 'go-mode))

test/go-compile-test.el

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
;;; go-compile-test.el --- unit tests for ‘go-mode’ compilation -*- lexical-binding: t; -*-
2+
3+
;; Copyright 2020 Google LLC
4+
;;
5+
;; Licensed under the Apache License, Version 2.0 (the "License");
6+
;; you may not use this file except in compliance with the License.
7+
;; You may obtain a copy of the License at
8+
;;
9+
;; https://www.apache.org/licenses/LICENSE-2.0
10+
;;
11+
;; Unless required by applicable law or agreed to in writing, software
12+
;; distributed under the License is distributed on an "AS IS" BASIS,
13+
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
;; See the License for the specific language governing permissions and
15+
;; limitations under the License.
16+
17+
;;; Commentary:
18+
19+
;; Unit tests for the ‘compilation-mode’ integration of ‘go-mode’.
20+
21+
;;; Code:
22+
23+
(require 'go-mode)
24+
25+
(require 'cl-lib)
26+
(require 'ert)
27+
28+
(ert-deftest go-greedy-test-pattern ()
29+
"Verify that https://github.com/dominikh/go-mode.el/issues/361 is fixed."
30+
;; ‘compilation-mode’ doesn’t have its own syntax table, so we use the
31+
;; standard one.
32+
(with-temp-buffer (go-mode)) ; initialize once
33+
(with-syntax-table (standard-syntax-table)
34+
(should-not (string-match-p
35+
(cadr (assq 'go-test compilation-error-regexp-alist-alist))
36+
"\nfile.go:1:2: word word"))))
37+
38+
(ert-deftest go-1.14-test-v ()
39+
"Verify that https://github.com/dominikh/go-mode.el/issues/362 is fixed."
40+
(with-temp-buffer (go-mode)) ; initialize once
41+
(with-syntax-table (standard-syntax-table)
42+
(cl-destructuring-bind (regexp file line)
43+
(cdr (assq 'go-test compilation-error-regexp-alist-alist))
44+
(let ((text " Test: foo_test.go:6: message"))
45+
(should (string-match regexp text))
46+
(should (equal (match-string file text) "foo_test.go"))
47+
(should (equal (match-string line text) "6"))))))
48+
49+
;;; go-compile-test.el ends here

0 commit comments

Comments
 (0)