test-is integration via SLIME

5 views
Skip to first unread message

Phil Hagelberg

unread,
Feb 18, 2009, 7:07:24 PM2/18/09
to clo...@googlegroups.com

I've been cooking up a little tool to help with running tests using
test-is. It's a little cumbersome to need to switch back and forth
between the test buffer and the repl to see the test results, so I've
created an Emacs mode that actually overlays the results on top of the
test buffer itself.

I've attached a screenshot of it in action. Basically it colors failing
"is" forms in red and erroring forms in brown. When you put the point in
a failing "is" form and press C-c ', it will show the failure message in
the minibuffer.

I find it to be very useful when writing tests to be able to get instant
feedback. And if it's easier to write tests, hopefully that means more
tests will get written. =)

http://github.com/technomancy/clojure-mode/blob/ef0f8f73a1b282aa28d160fd01e79794c8f15835/clojure-test-mode.el

Please try it out if you use SLIME and let me know how it works for
you. One serious caveat is that swank-clojure hasn't been updated to
work with clojure-trunk yet, so you'll need to use slightly older
versions of everything. Here's what I've got:

Clojure: git://github.com/kevinoneill/clojure.git revision d866f14
Contrib: git://github.com/technomancy/clojure-contrib.git revision 4802d99
Swank-clojure: git://github.com/jochu/swank-clojure.git revision 581954d
SLIME: git://github.com/nablaone/slime.git revision 5b8cb89

Hopefully the dust will settle soon, but for you've got to step lightly.

-Phil

clojure-test-mode.png

Stuart Sierra

unread,
Feb 18, 2009, 9:46:03 PM2/18/09
to Clojure
That's really nifty, Phil! I'll have to check it out.
-Stuart Sierra

On Feb 18, 7:07 pm, Phil Hagelberg <p...@hagelb.org> wrote:
> I've been cooking up a little tool to help with running tests using
> test-is. It's a little cumbersome to need to switch back and forth
> between the test buffer and the repl to see the test results, so I've
> created an Emacs mode that actually overlays the results on top of the
> test buffer itself.
>
> I've attached a screenshot of it in action. Basically it colors failing
> "is" forms in red and erroring forms in brown. When you put the point in
> a failing "is" form and press C-c ', it will show the failure message in
> the minibuffer.
>
> I find it to be very useful when writing tests to be able to get instant
> feedback. And if it's easier to write tests, hopefully that means more
> tests will get written. =)
>
>  http://github.com/technomancy/clojure-mode/blob/ef0f8f73a1b282aa28d16...
>
> Please try it out if you use SLIME and let me know how it works for
> you. One serious caveat is that swank-clojure hasn't been updated to
> work with clojure-trunk yet, so you'll need to use slightly older
> versions of everything. Here's what I've got:
>
> Clojure: git://github.com/kevinoneill/clojure.git revision d866f14
> Contrib: git://github.com/technomancy/clojure-contrib.git revision 4802d99
> Swank-clojure: git://github.com/jochu/swank-clojure.git revision 581954d
> SLIME: git://github.com/nablaone/slime.git revision 5b8cb89
>
> Hopefully the dust will settle soon, but for you've got to step lightly.
>
> -Phil
>
>  clojure-test-mode.png
> 59KViewDownload

Michel Salim

unread,
Feb 23, 2009, 11:51:01 PM2/23/09
to clo...@googlegroups.com
On Wed, Feb 18, 2009 at 7:07 PM, Phil Hagelberg <ph...@hagelb.org> wrote:
> I've been cooking up a little tool to help with running tests using
> test-is. It's a little cumbersome to need to switch back and forth
> between the test buffer and the repl to see the test results, so I've
> created an Emacs mode that actually overlays the results on top of the
> test buffer itself.
>
> I've attached a screenshot of it in action. Basically it colors failing
> "is" forms in red and erroring forms in brown. When you put the point in
> a failing "is" form and press C-c ', it will show the failure message in
> the minibuffer.
>
That would be really neat! I'm having a bit of trouble setting it up, though:

- I added the clojure-test initialization code to ~/.emacs right after
setting up clojure-mode
- When loading a .clj file in Emacs, it automatically triggers Slime
- However, the file is not actually loaded; I had to C-c C-l
- C-c C-' is not bound; if I (run-tests 'clojure-mode.test-is), the
tests run but nothing appears in the editor window

Any idea what could be wrong? Here's the clojure-mode /
clojure-test-mode part of ~/.emacs

(autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
(add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))
(autoload 'clojure-test-mode "clojure-test-mode" "Clojure test mode" t)
(add-hook 'clojure-mode-hook
(lambda () (save-excursion
(goto-char (point-min))
(if (or (search-forward "(deftest" nil t)
(search-forward "(with-test" nil t))
(clojure-test-mode t)))))

Thanks,

--
miʃel salim • http://hircus.jaiku.com/
IUCS • msa...@cs.indiana.edu
Fedora • sal...@fedoraproject.org
MacPorts • hir...@macports.org

Phil Hagelberg

unread,
Feb 24, 2009, 12:17:59 PM2/24/09
to clo...@googlegroups.com
Michel Salim <michel...@gmail.com> writes:

> That would be really neat! I'm having a bit of trouble setting it up,
> though:

> - When loading a .clj file in Emacs, it automatically triggers Slime

This should happen only on test files, not every clojure file.

> - However, the file is not actually loaded; I had to C-c C-l

Right; it doesn't load until you call clojure-test-run-tests, which is
bound to C-c C-,.

> - C-c C-' is not bound; if I (run-tests 'clojure-mode.test-is), the
> tests run but nothing appears in the editor window

C-c C-' is not bound; it should be C-c ' without control on the
quote. This should be called after you've run the tests to see the
details of the failure/error at point.

> Any idea what could be wrong? Here's the clojure-mode /
> clojure-test-mode part of ~/.emacs

Does "Test" show up in the modeline in your test buffers? If so then the
mode is activated correctly. I'm still working through some bugs that
surface unpredictably due to the asynchronous nature of SLIME, so if you
don't see anything be sure to try C-c C-, a number of times.

-Phil

Michel S.

unread,
Feb 24, 2009, 2:20:02 PM2/24/09
to Clojure


On Feb 24, 12:17 pm, Phil Hagelberg <p...@hagelb.org> wrote:
> Michel Salim <michel.syl...@gmail.com> writes:
> > That would be really neat! I'm having a bit of trouble setting it up,
> > though:
> > - When loading a .clj file in Emacs, it automatically triggers Slime
>
> This should happen only ontestfiles, not every clojure file.
Ah, right. It just happened that the first few files I tested have
some tests defined.

>
> > - However, the file is not actually loaded; I had to C-c C-l
>
> Right; it doesn't load until you call clojure-test-run-tests, which is
> bound to C-c C-,.
>
> > - C-c C-' is not bound; if I (run-tests 'clojure-mode.test-is), the
> > tests run but nothing appears in the editor window
>
> Does "Test" show up in the modeline in yourtestbuffers? If so then themodeis activated correctly. I'm still working through some bugs that
> surface unpredictably due to the asynchronous nature of SLIME, so if you
> don't see anything be sure to try C-c C-, a number of times.
>
That does the trick, yes. Sometimes none of the failing tests are
highlighted, sometimes some of them, and sometimes all. I misread the
explanation and assumed C-c ' is the command that does the
highlighting (rather than just showing the test error in the
minibuffer).

Thanks,

--
Michel
Reply all
Reply to author
Forward
0 new messages