Skip to content

Commit d98a53c

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 d98a53c

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
;;; go-compile-test.el --- unit tests for ‘go-mode’ compilation -*- lexical-binding: t; -*-
2+
3+
;; Copyright 2020 The go-mode Authors. All rights reserved. Use of
4+
;; this source code is governed by a BSD-style license that can be
5+
;; found in the LICENSE file.
6+
7+
;;; Commentary:
8+
9+
;; Unit tests for the ‘compilation-mode’ integration of ‘go-mode’.
10+
11+
;;; Code:
12+
13+
(require 'go-mode)
14+
15+
(require 'cl-lib)
16+
(require 'ert)
17+
18+
(ert-deftest go-greedy-test-pattern ()
19+
"Verify that https://github.com/dominikh/go-mode.el/issues/361 is fixed."
20+
;; ‘compilation-mode’ doesn’t have its own syntax table, so we use the
21+
;; standard one.
22+
(with-temp-buffer (go-mode)) ; initialize once
23+
(with-syntax-table (standard-syntax-table)
24+
(should-not (string-match-p
25+
(cadr (assq 'go-test compilation-error-regexp-alist-alist))
26+
"\nfile.go:1:2: word word"))))
27+
28+
(ert-deftest go-1.14-test-v ()
29+
"Verify that https://github.com/dominikh/go-mode.el/issues/362 is fixed."
30+
(with-temp-buffer (go-mode)) ; initialize once
31+
(with-syntax-table (standard-syntax-table)
32+
(cl-destructuring-bind (regexp file line)
33+
(cdr (assq 'go-test compilation-error-regexp-alist-alist))
34+
(let ((text " Test: foo_test.go:6: message"))
35+
(should (string-match regexp text))
36+
(should (equal (match-string file text) "foo_test.go"))
37+
(should (equal (match-string line text) "6"))))))
38+
39+
;;; go-compile-test.el ends here

0 commit comments

Comments
 (0)