tdrhq / slite

a SLIme-based TEst runner for FiveAM and Parachute Tests
Apache License 2.0
50 stars 4 forks source link

Run test at point #5

Open Ambrevar opened 2 years ago

Ambrevar commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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)))))))