Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Lamirault <[email protected]>
  • Loading branch information
nlamirault committed Nov 9, 2015
2 parents 0fc2f83 + be24c85 commit 2367744
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 41 deletions.
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ try to follow these guidelines when you do so.

## Pull requests

* Read [how to properly contribute to open source projects on Github][2].
* Use a topic branch to easily amend a pull request later, if necessary.
* Write [good commit messages][3].
* Use the same coding conventions as the rest of the project.
* Verify your Emacs Lisp code with `checkdoc`.
* Open a [pull request][4] that relates to *only* one subject with a clear title
and description in grammatically correct, complete sentences.
and description in grammatically correct, complete sentences. (Target branch
must be `develop` branch.


[1]: https://github.com/nlamirault/gotest.el/issues
Expand Down
96 changes: 61 additions & 35 deletions gotest.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

(require 's)
(require 'f)
(require 'cl)
(require 'go-mode)


Expand All @@ -51,39 +52,6 @@ See https://getgb.io."
:type 'string
:group 'gotest)


;; (defvar go-test-compilation-error-regexp-alist-alist
;; '((go-test-testing . ("^\t\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\): .*$" 1 2)) ;; stdlib package testing
;; (go-test-testify . ("^\tLocation:\t\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\)$" 1 2)) ;; testify package assert
;; (go-test-gopanic . ("^\t\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\) \\+0x\\(?:[0-9a-f]+\\)" 1 2)) ;; panic()
;; (go-test-compile . ("^\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\):\\([0-9]+\\): .*$" 1 2 3)) ;; go compiler
;; (go-test-linkage . ("^\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\): undefined: .*$" 1 2))) ;; go linker
;; "Alist of values for `go-test-compilation-error-regexp-alist'.
;; See also: `compilation-error-regexp-alist-alist'.")

;; (defcustom go-test-compilation-error-regexp-alist
;; '(go-test-testing
;; go-test-testify
;; go-test-gopanic
;; go-test-compile
;; go-test-linkage)
;; "Alist that specifies how to match errors in go test output.
;; The default set of regexps should only match the output of the
;; standard `go' tool, which includes compile, link, stacktrace (panic)
;; and package testing. There is support for matching error output
;; from other packages, such as `testify'.

;; Only file names ending in `.go' will be matched by default.

;; Instead of an alist element, you can use a symbol, which is
;; looked up in `go-testcompilation-error-regexp-alist-alist'.

;; See also: `compilation-error-regexp-alist'."
;; :type '(repeat (choice (symbol :tag "Predefined symbol")
;; (sexp :tag "Error specification")))
;; :group 'gotest)


(defvar-local go-test-args nil
"Arguments to pass to go test.
This variable is buffer-local, set using .dir-locals.el for example.")
Expand Down Expand Up @@ -178,6 +146,50 @@ See https://getgb.io."
(message "Go Test finished.")))


(defvar go-test-regexp-prefix
"^[[:space:]]*func[[:space:]]\\(([^()]*?)\\)?[[:space:]]*\\("
"The prefix of the go-test regular expression.")

(defvar go-test-regexp-suffix
"[[:alpha:][:digit:]_]*\\)("
"The suffix of the go-test regular expression.")

(defvar go-test-prefixes '("Test" "Example")
"Prefixes to use when searching for tests.")


(defvar go-test-compilation-error-regexp-alist-alist
'((go-test-testing . ("^\t\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\): .*$" 1 2)) ;; stdlib package testing
(go-test-testify . ("^\tLocation:\t\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\)$" 1 2)) ;; testify package assert
(go-test-gopanic . ("^\t\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\) \\+0x\\(?:[0-9a-f]+\\)" 1 2)) ;; panic()
(go-test-compile . ("^\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\):\\([0-9]+\\): .*$" 1 2 3)) ;; go compiler
(go-test-linkage . ("^\\([[:alnum:]-_/.]+\\.go\\):\\([0-9]+\\): undefined: .*$" 1 2))) ;; go linker
"Alist of values for `go-test-compilation-error-regexp-alist'.
See also: `compilation-error-regexp-alist-alist'.")

(defcustom go-test-compilation-error-regexp-alist
'(go-test-testing
go-test-testify
go-test-gopanic
go-test-compile
go-test-linkage)
"Alist that specifies how to match errors in go test output.
The default set of regexps should only match the output of the
standard `go' tool, which includes compile, link, stacktrace (panic)
and package testing. There is support for matching error output
from other packages, such as `testify'.
Only file names ending in `.go' will be matched by default.
Instead of an alist element, you can use a symbol, which is
looked up in `go-testcompilation-error-regexp-alist-alist'.
See also: `compilation-error-regexp-alist'."
:type '(repeat (choice (symbol :tag "Predefined symbol")
(sexp :tag "Error specification")))
:group 'gotest)


;; Commands
;; -----------

Expand Down Expand Up @@ -247,10 +259,24 @@ For example, if the current buffer is `foo.go', the buffer for
(setq name (thing-at-point 'word))))
name))


(defun go-test--get-current-test ()
"Return the current test name."
(go-test--get-current-data "Test"))
(save-excursion
(end-of-line)
(if (cl-loop for test-prefix in go-test-prefixes
thereis (search-backward-regexp
(format "%s%s%s"
go-test-regexp-prefix test-prefix
go-test-regexp-suffix) nil t))
(if (> (length (match-string-no-properties 1)) 0)
(concat "Test" (s-replace ")" "" (cadr (s-split "*" (match-string-no-properties 1)))))
(match-string-no-properties 2))
(error "Unable to find a test"))))


;; (defun go-test--get-current-test ()
;; "Return the current test name."
;; (go-test--get-current-data "Test"))


(defun go-test--get-current-benchmark ()
Expand Down
14 changes: 13 additions & 1 deletion test/go_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package test

import "testing"
import (
"testing"

"github.com/stretchr/testify/suite"
)

func TestFoo(t *testing.T) {
t.Log("logFoo")
Expand All @@ -13,3 +17,11 @@ func TestBar(t *testing.T) {
func Test_Baz(t *testing.T) {
t.Log("log_Baz")
}

type Suite struct {
suite.Suite
}

func (s *Suite) TestIndividualTest() {
s.T().Log("logSuite")
}
8 changes: 8 additions & 0 deletions test/gotest-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@
(re-search-forward "logFoo")
(should (string= "TestFoo" (go-test--get-current-test)))))))

(ert-deftest test-go-test-get-current-test-when-suite-test ()
:tags '(find)
(with-test-sandbox
(with-current-buffer (find-file-noselect testsuite-buffer-name)
(save-excursion
(re-search-forward "logSuite")
(should (string= "TestSuite" (go-test--get-current-test)))))))

(ert-deftest test-go-test-get-current-file-tests ()
:tags '(find)
(with-test-sandbox
Expand Down
Binary file added test/test.test
Binary file not shown.
9 changes: 7 additions & 2 deletions var/foo.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
mode: set
_/Users/nicolas/Projects/gotest.el/var/foo.go:7.13,9.2 1 0
package main

import "fmt"

func main() {
fmt.Println("Hello gotest.el")
}

0 comments on commit 2367744

Please sign in to comment.