doom-emacs/modules/lang/go/autoload.el

52 lines
1.2 KiB
EmacsLisp
Raw Normal View History

;;; lang/go/autoload.el -*- lexical-binding: t; -*-
2017-03-20 07:49:13 +00:00
2017-04-07 05:45:57 +00:00
;;
;; Tests
2017-03-20 07:49:13 +00:00
(defvar +go-test-last nil
"The last test run.")
2019-07-31 10:06:56 +00:00
(defun +go--spawn (cmd)
(require 'async)
2017-03-20 07:49:13 +00:00
(save-selected-window
2019-07-31 10:06:56 +00:00
(async-shell-command cmd)))
(defun +go--run-tests (args)
(let ((cmd (concat "go test " args)))
(setq +go-test-last (concat "cd " default-directory ";" cmd))
(+go--spawn cmd)))
2017-03-20 07:49:13 +00:00
;;;###autoload
(defun +go/test-rerun ()
(interactive)
(if +go-test-last
2019-07-31 10:06:56 +00:00
(+go--spawn +go-test-last)
(+go/test-all)))
2017-03-20 07:49:13 +00:00
;;;###autoload
(defun +go/test-all ()
(interactive)
(+go--run-tests ""))
;;;###autoload
(defun +go/test-nested ()
(interactive)
(+go--run-tests "./..."))
;;;###autoload
(defun +go/test-single ()
(interactive)
(if (string-match "_test\\.go" buffer-file-name)
(save-excursion
(re-search-backward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?[[:alnum:]]+)[ ]+\\)?\\(Test[[:alnum:]_]+\\)(.*)")
(+go--run-tests (concat "-run" "='" (match-string-no-properties 2) "'")))
(error "Must be in a _test.go file")))
;;;###autoload
(defun +go/play-buffer-or-region (&optional beg end)
"TODO"
(interactive "r")
(if (use-region-p)
(go-play-region beg end)
(go-play-buffer)))