From: Jeffery Zhang
Subject: Automatic Unit Testing hotkey?
Date: 
Message-ID: <e2ngdl$nhs$1@ruby.cit.cornell.edu>
I'm not terribly familiar with the exact working of Emacs+Slime+Lisp, 
so i don't know if this is possible. Here is the usable scenerio I 
envision:

I'm writing some hard to code function foo, I need to do a lot of unit 
testing frequently. So I write a unit testing framework and a bunch of 
unit tests, say I would normally type:
(unit-test foo) in REPL to run the tests.

The output is done with (format t ...) and generates a bunch of stuff.

When typing in a lisp file buffer, I can compile and load the current 
defun into the environment with C-c C-c, I would like to be able to do 
something like F2 to compile, load, and run the unit tests and pipe the 
output to a separate buffer. And be able to press F2 to switch back to 
where I was in the lisp file buffer to make changes.

Towards this end, I'm wondering if it's possible for emacs to directly 
send an expression to the REPL (so if my cursor is over the definition 
for foo, it would send (unit-test foo) to the REPL and pipe any output 
from evaluating this expression to a separate buffer).

-Jeffery

From: Thomas Atkins
Subject: Re: Automatic Unit Testing hotkey?
Date: 
Message-ID: <1146091363.490522.92700@t31g2000cwb.googlegroups.com>
While this is not exactly what you are after, it might point you in the
right direction.

(defvar slime-run-test-function '(sb-rt:do-tests))
(defvar slime-test-setup-function '())
(defvar slime-clear-test-function '(sb-rt:rem-all-tests))
(defun slime-sb-rt-clear-tests ()
  (interactive)
  (slime-eval slime-clear-test-function))
(defun slime-sb-rt-do-tests ()
  (interactive)
  (slime-eval slime-test-setup-function)
  (if (slime-eval slime-run-test-function)
      (message "All(%d) tests passed" (slime-eval '(cl:1- (cl:length
sb-rt::*entries*))))
      (slime-repl)))
(global-set-key [f5] 'slime-sb-rt-clear-tests)
(global-set-key [f6] 'slime-sb-rt-do-tests)
From: Thomas Schilling
Subject: Re: Automatic Unit Testing hotkey?
Date: 
Message-ID: <4b9urjFvp35fU1@news.dfncis.de>
You might better ask at the slime mailing list, but at taking a look at
the slime source code tells you:

  (defun slime-eval-last-expression ()
    "Evaluate the expression preceding point."
    (interactive)
    (slime-interactive-eval (slime-last-expression)))

So as a start you could add your own function (to init.el) looking like
this (untested):

  (defun unit-test-symbol-at-point ()
    "Run unit test for symbol at point"
    (interactive)
    (slime-interactive-eval
      (format "(unit-test '%s)" (symbol-at-point))))

and then bind it to f2.

That however doesn't solve the output stream issue.  You might want to
take a look at how the compilation notes buffer is implemented and use
this as a starting point.  The slime code is also very readable, so
don't be afraid of taking a closer look at it.  Or, as said, ask at the
slime mailing list.

-ts