Skip to content

Instantly share code, notes, and snippets.

@psanford
Last active July 23, 2021 17:48
Show Gist options
  • Save psanford/d175c10ca28b1566de358fe336a9fb2f to your computer and use it in GitHub Desktop.
Save psanford/d175c10ca28b1566de358fe336a9fb2f to your computer and use it in GitHub Desktop.

Revisions

  1. psanford revised this gist Jul 23, 2021. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions go-test.el
    Original file line number Diff line number Diff line change
    @@ -47,3 +47,11 @@
    (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)))
  2. psanford revised this gist Jul 23, 2021. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions go-test.el
    Original file line number Diff line number Diff line change
    @@ -27,3 +27,23 @@
    (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))))

  3. psanford created this gist Jul 23, 2021.
    29 changes: 29 additions & 0 deletions go-test.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    (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))))))