Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subtest support #87

Open
chmouel opened this issue Nov 4, 2021 · 1 comment
Open

subtest support #87

chmouel opened this issue Nov 4, 2021 · 1 comment

Comments

@chmouel
Copy link

chmouel commented Nov 4, 2021

It would be nice if there was a way to suport testsuite subtest, I currently have this hack where if I detect the current line as "name": "name of test",

it will run the testname with "/name_of_test" appended to gotest, this hack look like this :

(defun my-gotest-maybe-ts-run()
    (interactive)
    (let ((testrunname)
          (gotest (cadr (go-test--get-current-test-info))))
      (save-excursion
        (goto-char (line-beginning-position))
        (re-search-forward "name:[[:blank:]]*\"\\([^\"]*\\)\"" (line-end-position) t))
      (setq testrunname (match-string-no-properties 1))
      (if testrunname
          (setq gotest (format "%s/%s" gotest (shell-quote-argument
                                               (replace-regexp-in-string " " "_" testrunname)))))
      (go-test--go-test (concat "-run " gotest "\\$ ."))))

this works relatively well but that's really depend if the user is on the "name" line and I wonder if this could make it smarter before submitting it.

perhaps the only way to know that properly is to do this with tree-sitter or see if lsp can help.

@ahobson
Copy link

ahobson commented Jun 30, 2023

This is what I'm using and it seems to work ok so far:

(defun my-go-test--get-current-subtest-info ()
  "Find subtest."
  (save-excursion
    (end-of-line)
    (let ((gotest-before-search (cadr (go-test--get-current-test-info))))
      (if (search-backward-regexp "suite.Run(\"\\([^,]*\\)\"" nil t)
          (let ((subtest-match (match-string-no-properties 1))
                (gotest (cadr (go-test--get-current-test-info))))
            (if (string= gotest gotest-before-search)
                (shell-quote-argument
                 (format ".*/%s/%s$" gotest
                         (replace-regexp-in-string "[[:space:]]" "_" subtest-match)))))))))

(defun my-gotest-current-test ()
  "Launch subtest if found, otherwise run current test."
    (interactive)
    (let ((subtest (my-go-test--get-current-subtest-info)))
      (if subtest
          (go-test--go-test (concat "-run " subtest " ."))
        (go-test-current-test))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants