Skip to content

Commit

Permalink
Fix ‘go-test’ compilation message pattern.
Browse files Browse the repository at this point in the history
Fixes dominikh#361, dominikh#362

Restrict the prefix and filename pattern (Bug dominikh#361), and also allow for a test
name prefix (Bug dominikh#362).

Add regression tests for these bugs.
  • Loading branch information
phst committed May 10, 2020
1 parent 734d523 commit 4bbd739
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
12 changes: 10 additions & 2 deletions go-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1841,8 +1841,16 @@ with goflymake (see URL `https://github.com/dougm/goflymake'), gocode
(when (and (boundp 'compilation-error-regexp-alist)
(boundp 'compilation-error-regexp-alist-alist))
(add-to-list 'compilation-error-regexp-alist 'go-test)
(add-to-list 'compilation-error-regexp-alist-alist
'(go-test . ("^\\s-+\\([^()\t\n]+\\):\\([0-9]+\\):? .*$" 1 2)) t)))
(add-to-list
'compilation-error-regexp-alist-alist
`(go-test . (,(concat "^[ \t]+" ; prefix
;; Optional test name (for go test -v):
"\\(?:[./_[:alpha:]][-./_+%@[:alnum:]]*: \\)?"
"\\([./_[:alpha:]][-./_+%@[:alnum:]]*\\):" ; file
"\\([0-9]+\\):?" ; line
" .*$")
1 2))
t)))

;;;###autoload
(add-to-list 'auto-mode-alist (cons "\\.go\\'" 'go-mode))
Expand Down
49 changes: 49 additions & 0 deletions test/go-compile-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
;;; go-compile-test.el --- unit tests for ‘go-mode’ compilation -*- lexical-binding: t; -*-

;; Copyright 2020 Google LLC
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; https://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.

;;; Commentary:

;; Unit tests for the ‘compilation-mode’ integration of ‘go-mode’.

;;; Code:

(require 'go-mode)

(require 'cl-lib)
(require 'ert)

(ert-deftest go-greedy-test-pattern ()
"Verify that https://github.com/dominikh/go-mode.el/issues/361 is fixed."
;; ‘compilation-mode’ doesn’t have its own syntax table, so we use the
;; standard one.
(with-temp-buffer (go-mode)) ; initialize once
(with-syntax-table (standard-syntax-table)
(should-not (string-match-p
(cadr (assq 'go-test compilation-error-regexp-alist-alist))
"\nfile.go:1:2: word word"))))

(ert-deftest go-1.14-test-v ()
"Verify that https://github.com/dominikh/go-mode.el/issues/362 is fixed."
(with-temp-buffer (go-mode)) ; initialize once
(with-syntax-table (standard-syntax-table)
(cl-destructuring-bind (regexp file line)
(cdr (assq 'go-test compilation-error-regexp-alist-alist))
(let ((text " Test: foo_test.go:6: message"))
(should (string-match regexp text))
(should (equal (match-string file text) "foo_test.go"))
(should (equal (match-string line text) "6"))))))

;;; go-compile-test.el ends here

0 comments on commit 4bbd739

Please sign in to comment.