Skip to content

Fix ‘go-test’ compilation message pattern. #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 39 additions & 0 deletions test/go-compile-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
;;; go-compile-test.el --- unit tests for ‘go-mode’ compilation -*- lexical-binding: t; -*-

;; Copyright 2020 The go-mode Authors. All rights reserved. Use of
;; this source code is governed by a BSD-style license that can be
;; found in the LICENSE file.

;;; 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