Last active
July 23, 2021 17:48
-
-
Save psanford/d175c10ca28b1566de358fe336a9fb2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun pms-go-run-test (&optional more-test-args) | |
"Runs tests for current package" | |
(interactive) | |
(when (buffer-file-name) | |
(save-buffer)) | |
(compile (concat "go test -v -count=1 -mod=mod" more-test-args) 'go-compilation) | |
(ring-insert pms-previous-test-ring | |
(cons | |
`(lambda () (pms-go-run-test ,more-test-args)) | |
(current-buffer)))) | |
(defun pms-go-single-test-function (&optional more-test-args) | |
"Runs the current test function only" | |
(interactive) | |
(save-excursion | |
(let ((func-name (go--function-name))) | |
(when (not (string-prefix-p "Test" func-name)) | |
(error "Not in a test function: %s" func-name)) | |
(compile (concat "go test -v -count=1 -mod=mod -run ^" func-name "$" more-test-args) 'go-compilation) | |
(ring-insert pms-previous-test-ring | |
(cons | |
`(lambda () (pms-go-run-test ,more-test-args)) | |
(current-buffer)))))) | |
(defvar pms-previous-test-ring (make-ring 5)) | |
(defun pms-run-last-test (&optional n) | |
"Run most recently run test again" | |
(interactive "P") | |
(when (buffer-file-name) | |
(save-buffer)) | |
(setq n | |
(cond | |
((null n) 0) | |
((listp n) 1) | |
(1 n))) | |
(let ((prev (ring-ref pms-previous-test-ring n))) | |
(if (> n 0) | |
(ring-insert pms-previous-test-ring prev)) | |
(let ((command (car prev)) | |
(buffer (cdr prev))) | |
(switch-to-buffer buffer) | |
(funcall command)))) | |
(add-to-list 'compilation-error-regexp-alist-alist | |
'(go-compilation | |
"\\([^[:space:]\n:]+\\.go\\):\\([0-9]+\\)" 1 2)) | |
(define-compilation-mode go-compilation "Go Compile" | |
"Compilation mode for go" | |
(set (make-local-variable 'compilation-error-regexp-alist) '(go-compilation))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment