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

Run test at point #5

Open
Ambrevar opened this issue May 28, 2022 · 2 comments
Open

Run test at point #5

Ambrevar opened this issue May 28, 2022 · 2 comments

Comments

@Ambrevar
Copy link

A feature I miss with Parachute (I haven't tried FiveAM) is the ability to easily run the single test I'm writing (or "the test at point"). Unless I'm missing something, the quickest way is to switch to a repl and run

(parachute:test 'my-package::my-test)

But if you do this a lot the back and forth switching quickly gets tiring...

Enters Slite with its convenient interface. Turns out that what I want fits in this very short function:

(defun slite-run-at-point (&optional raw-prefix-arg)
  "See `sly-compile-defun' for RAW-PREFIX-ARG."
  (interactive "P")
  (call-interactively 'sly-compile-defun)
  (slite-run
   (prin1-to-string
    `(parachute:test
      ,(let ((name (sly-parse-toplevel-form)))
         (if (symbolp name)
             `(quote ,(intern (sly-qualify-cl-symbol-name name)))
           name))))))

Now place the point on any test form and call slite-run-at-point.

What do you think?

@tdrhq
Copy link
Owner

tdrhq commented May 28, 2022

This makes sense. For me, usually I use FiveAM, and before a coding session I set up a Slite run with something like (fiveam:run :my-test-suite-name), so from that point onward I just do (C-c C-v .. or actually the undocumented C-c C-j, undocumented because it's a little buggy, to just run the previous test in my history).

But I think it makes sense to have a run-test-at-point. I wonder how we could make this work on both parachute and fiveam? Maybe make a reasonable guess looking up the tests from both fiveam and parachute?

@Ambrevar
Copy link
Author

I forgot to explain the use case: when the test suite is slow and you are working on the tests iteratively. You don't want to run the full suite every time because it takes too long.

About framework detection, maybe we could infer the suite based on the top-level first expression? Untested:

(defun slite-run-at-point (&optional raw-prefix-arg)
  "See `sly-compile-defun' for RAW-PREFIX-ARG."
  (interactive "P")
  (call-interactively 'sly-compile-defun)
  (slite-run
   (cl-flet ((top-level-first-sexp
              ()
              (ignore-errors
                (save-excursion
                  (goto-char (car (sly-region-for-defun-at-point)))
                  (down-list 1)
                  (car (last (sly-parse-context (read (current-buffer)))))))))
     (prin1-to-string
      `(,(cond
          ((let ((case-fold-search t))
             (string-match-p "define-test$" (symbol-name (top-level-first-sexp)) ))
           'parachute:test)
          (t
           'fiveam:run))
        ,(let ((name (sly-parse-toplevel-form)))
           (if (symbolp name)
               `',(intern (sly-qualify-cl-symbol-name name))
             name)))))))

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