2016-01-18 03:06:04 +00:00
|
|
|
;;; funcs.el --- Go Layer functions File for Spacemacs
|
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
2016-01-18 03:06:04 +00:00
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
(defun load-gopath-file(gopath name)
|
|
|
|
"Search for NAME file in all paths referenced in GOPATH."
|
|
|
|
(let* ((sep (if (spacemacs/system-is-mswindows) ";" ":"))
|
|
|
|
(paths (split-string gopath sep))
|
|
|
|
found)
|
2018-01-07 02:38:13 +00:00
|
|
|
(cl-loop for p in paths
|
2016-01-18 03:06:04 +00:00
|
|
|
for file = (concat p name) when (file-exists-p file)
|
|
|
|
do
|
|
|
|
(load-file file)
|
|
|
|
(setq found t)
|
|
|
|
finally return found)))
|
2016-04-30 02:58:23 +00:00
|
|
|
|
|
|
|
(defun spacemacs//go-enable-gometalinter ()
|
|
|
|
"Enable `flycheck-gometalinter' and disable overlapping `flycheck' linters."
|
|
|
|
(setq flycheck-disabled-checkers '(go-gofmt
|
|
|
|
go-golint
|
|
|
|
go-vet
|
|
|
|
go-build
|
|
|
|
go-test
|
|
|
|
go-errcheck))
|
|
|
|
(flycheck-gometalinter-setup))
|
2017-05-25 11:20:36 +00:00
|
|
|
|
|
|
|
(defun spacemacs/go-run-tests (args)
|
|
|
|
(interactive)
|
|
|
|
(compilation-start (concat "go test " args " " go-use-test-args)
|
|
|
|
nil (lambda (n) go-test-buffer-name) nil))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-package-tests ()
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/go-run-tests ""))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-package-tests-nested ()
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/go-run-tests "./..."))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-test-current-function ()
|
|
|
|
(interactive)
|
|
|
|
(if (string-match "_test\\.go" buffer-file-name)
|
|
|
|
(let ((test-method (if go-use-gocheck-for-testing
|
|
|
|
"-check.f"
|
|
|
|
"-run")))
|
|
|
|
(save-excursion
|
|
|
|
(re-search-backward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?[[:alnum:]]+)[ ]+\\)?\\(Test[[:alnum:]_]+\\)(.*)")
|
|
|
|
(spacemacs/go-run-tests (concat test-method "='" (match-string-no-properties 2) "$'"))))
|
|
|
|
(message "Must be in a _test.go file to run go-run-test-current-function")))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-test-current-suite ()
|
|
|
|
(interactive)
|
|
|
|
(if (string-match "_test\.go" buffer-file-name)
|
|
|
|
(if go-use-gocheck-for-testing
|
|
|
|
(save-excursion
|
|
|
|
(re-search-backward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?\\([[:alnum:]]+\\))[ ]+\\)?Test[[:alnum:]_]+(.*)")
|
|
|
|
(spacemacs/go-run-tests (concat "-check.f='" (match-string-no-properties 2) "'")))
|
|
|
|
(message "Gocheck is needed to test the current suite"))
|
|
|
|
(message "Must be in a _test.go file to run go-test-current-suite")))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-main ()
|
|
|
|
(interactive)
|
|
|
|
(shell-command
|
|
|
|
(format "go run %s"
|
2017-08-14 11:25:31 +00:00
|
|
|
(shell-quote-argument (or (file-remote-p (buffer-file-name (buffer-base-buffer)) 'localname)
|
|
|
|
(buffer-file-name (buffer-base-buffer)))))))
|