Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created December 16, 2022 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmouel/608d93413849f58e44669a2c15ffc102 to your computer and use it in GitHub Desktop.
Save chmouel/608d93413849f58e44669a2c15ffc102 to your computer and use it in GitHub Desktop.
(defun golang-test-detect (&optional rg-extras)
(interactive)
(let ((results))
(with-temp-buffer
(insert (shell-command-to-string "rg -g '*_test.go' '^func\sTest'"))
(goto-char (point-min))
(while (re-search-forward "^\\(.+\\):func \\([a-zA-Z_]*\\)" nil t)
(let ((filename (match-string 2)))
(push (format "%s :: %s" (match-string 1) (match-string 2)) results))))
results))
(defun golang-test-run()
(interactive)
(let ((current-dir default-directory)
(result (completing-read "Choose a Test: " (golang-test-detect))))
(when (string-match "^\\(.*\\) :: \\(.+\\)" result)
(let ((default-directory (format "%s/%s" current-dir (file-name-directory (match-string 1 result)))))
(compile (format "eval $(pass show pac/vars/scratchtest);go test -v -tags e2e -count=1 -failfast -run \"^%s$\"|snazy -r \"^(===|---) (RUN|PASS)\" -r \"(error|ERROR)\"" (message (match-string 2 result))) t)))))
(require 'ansi-color)
(defun colorize-compilation-buffer ()
(toggle-read-only)
(ansi-color-apply-on-region compilation-filter-start (point))
(toggle-read-only))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
(let ((default-directory (expand-file-name "~/GIT/go/src/github.com/openshift-pipelines/pipelines-as-code")))
(golang-test-run))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment