2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/go/autoload.el -*- lexical-binding: t; -*-
|
2017-03-20 03:49:13 -04:00
|
|
|
|
2017-04-07 01:45:57 -04:00
|
|
|
;;
|
|
|
|
;; Tests
|
|
|
|
|
2017-03-20 03:49:13 -04:00
|
|
|
(defvar +go-test-last nil
|
|
|
|
"The last test run.")
|
|
|
|
|
2019-07-31 11:06:56 +01:00
|
|
|
(defun +go--spawn (cmd)
|
2017-03-20 03:49:13 -04:00
|
|
|
(save-selected-window
|
2019-08-27 11:02:57 +01:00
|
|
|
(compile cmd)))
|
2019-07-31 11:06:56 +01:00
|
|
|
|
|
|
|
(defun +go--run-tests (args)
|
2022-08-03 20:31:42 +01:00
|
|
|
(let ((cmd (concat "go test -test.v " args)))
|
2019-07-31 11:06:56 +01:00
|
|
|
(setq +go-test-last (concat "cd " default-directory ";" cmd))
|
|
|
|
(+go--spawn cmd)))
|
2017-03-20 03:49:13 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +go/test-rerun ()
|
|
|
|
(interactive)
|
|
|
|
(if +go-test-last
|
2019-07-31 11:06:56 +01:00
|
|
|
(+go--spawn +go-test-last)
|
|
|
|
(+go/test-all)))
|
2017-03-20 03:49:13 -04: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:]_]+\\)(.*)")
|
2022-05-12 17:07:04 +01:00
|
|
|
(+go--run-tests (concat "-run" "='^\\Q" (match-string-no-properties 2) "\\E$'")))
|
2017-03-20 03:49:13 -04:00
|
|
|
(error "Must be in a _test.go file")))
|
|
|
|
|
2022-08-03 20:31:42 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun +go/test-file ()
|
|
|
|
(interactive)
|
|
|
|
(if (string-match "_test\\.go" buffer-file-name)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(let ((func-list))
|
|
|
|
(while (re-search-forward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?[[:alnum:]]+)[ ]+\\)?\\(Test[[:alnum:]_]+\\)(.*)" nil t)
|
|
|
|
(push (match-string-no-properties 2) func-list))
|
|
|
|
(+go--run-tests (concat "-run" "='^(" (string-join func-list "|") ")$'"))))
|
|
|
|
(error "Must be in a _test.go file")))
|
|
|
|
|
2020-02-09 10:58:49 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun +go/bench-all ()
|
|
|
|
(interactive)
|
|
|
|
(+go--run-tests "-test.run=NONE -test.bench=\".*\""))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +go/bench-single ()
|
|
|
|
(interactive)
|
|
|
|
(if (string-match "_test\\.go" buffer-file-name)
|
|
|
|
(save-excursion
|
|
|
|
(re-search-backward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?[[:alnum:]]+)[ ]+\\)?\\(Benchmark[[:alnum:]_]+\\)(.*)")
|
2022-05-12 17:07:04 +01:00
|
|
|
(+go--run-tests (concat "-test.run=NONE -test.bench" "='^\\Q" (match-string-no-properties 2) "\\E$'")))
|
2020-02-09 10:58:49 +01:00
|
|
|
(error "Must be in a _test.go file")))
|
|
|
|
|
|
|
|
|
2018-12-23 23:54:27 -05:00
|
|
|
;;;###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)))
|