diff --git a/go-mode.el b/go-mode.el index 6340fa29..78218807 100644 --- a/go-mode.el +++ b/go-mode.el @@ -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)) diff --git a/test/go-compile-test.el b/test/go-compile-test.el new file mode 100644 index 00000000..0d3fa91c --- /dev/null +++ b/test/go-compile-test.el @@ -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