Skip to content

Commit

Permalink
go-build add options: tags and i
Browse files Browse the repository at this point in the history
  • Loading branch information
drewwells committed Aug 18, 2015
1 parent 883f77f commit f9d4eb7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
24 changes: 20 additions & 4 deletions flycheck.el
Expand Up @@ -6249,14 +6249,30 @@ See URL `http://golang.org/cmd/go/' and URL
:message (if have-vet "present" "missing")
:face (if have-vet 'success '(bold error)))))))

(flycheck-def-option-var flycheck-go-build-install-deps nil go-build
"Instruct go build to install dependencies `go build -i'."
:type 'boolean
:safe #'booleanp
:package-version '(flycheck . "0.24"))

(flycheck-def-option-var flycheck-go-build-tags nil go-build
"Instruct go build to apply build sentinels `go build -tags 'dev debug'."
:type '(repeat (string :tag "Tag"))
:safe #'flycheck-string-list-p
:package-version '(flycheck . "0.24"))

(flycheck-define-checker go-build
"A Go syntax and type checker using the `go build' command.

See URL `http://golang.org/cmd/go'."
;; We need to use `temporary-file-name' instead of `null-device', because Go
;; can't write to the null device. It's “too magic”. See
;; https://code.google.com/p/go/issues/detail?id=4851 for details.
:command ("go" "build" "-o" temporary-file-name)
;; We need to use `temporary-file-name' instead of `null-device',
;; because Go can't write to the null device.
;; See https://github.com/golang/go/issues/4851
:command ("go" "build"
(option-flag "-i" flycheck-go-build-install-deps)
;; multiple tags are listed as "dev debug ..."
(option-list "-tags=" flycheck-go-build-tags concat)
"-o" temporary-file-name)
:error-patterns
((error line-start (file-name) ":" line ":"
(optional column ":") " "
Expand Down
12 changes: 12 additions & 0 deletions test/flycheck-test.el
Expand Up @@ -4257,6 +4257,18 @@ See https://github.com/flycheck/flycheck/issues/531 and Emacs bug #19206"))
(flycheck-ert-resource-filename
"checkers/emacs-lisp-syntax-error.el")))))

(flycheck-ert-def-checker-test go-build go build-tags
(let* ((go-root (or (getenv "GOROOT") "/usr/local/go"))
(go-root-pkg (concat go-root "/src"))
(flycheck-go-build-tags '("dev")))
(flycheck-ert-with-env '(("GOPATH" . nil))
(flycheck-ert-should-syntax-check
"checkers/go/src/tags/main.go" 'go-mode
`(4 2 error ,(format "it ran)"
go-root-pkg)
:checker go-build)))))


(ert-deftest flycheck-go-package-name/package-file ()
:tags '(language-go)
(flycheck-ert-with-env
Expand Down
9 changes: 9 additions & 0 deletions test/resources/checkers/go/src/tags/main.go
@@ -0,0 +1,9 @@
// +build dev

package main

import "fmt"

func main() {
fmt.Println("it ran")
}

0 comments on commit f9d4eb7

Please sign in to comment.