back

Elisp function to run Golang unit tests in notes

2022-03-02

A elisp function to run a unit test. Put the function in ~/.emacs

  (defun go-run-unit-test ()
    (interactive)
    (let ((lineStr ""))
(if (string= (thing-at-point 'word) "func")
   (setq lineStr (thing-at-point 'word))
 (progn
   (search-backward "func")
   (setq lineStr (thing-at-point 'line))))

(let ((funcName (string-trim-left (car (split-string (thing-at-point 'line) "(")) "^func\s")))
 (start-process "GOTEST" "*GOTEST*" "go" "test" "-run" (concat "^" funcName "$")))))
go-run-unit-test