Skip to content

Commit

Permalink
added "clack.test" for unit testing Clack Applications. and rewrote "…
Browse files Browse the repository at this point in the history
…clack.test.suite" with it.
  • Loading branch information
fukamachi committed Jan 30, 2011
1 parent 881ed35 commit f84dde1
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 208 deletions.
3 changes: 2 additions & 1 deletion clack.asd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
((:file "hunchentoot")
#+(or allegro cmu lispworks sbcl)
(:file "apache")))
(:file "test/suite")))
(:file "test")
(:file "test/suite" :depends-on ("test"))))
(:module "contrib"
:depends-on ("core")
:serial t
Expand Down
48 changes: 48 additions & 0 deletions src/core/test.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#|
This file is a part of Clack package.
URL: http://github.com/fukamachi/clack
Copyright (c) 2011 Eitarow Fukamachi <e.arrows@gmail.com>
Clack is freely distributable under the LLGPL License.
|#

#|
Testing Clack Applications.
Author: Eitarow Fukamachi (e.arrows@gmail.com)
|#

(in-package :cl-user)

(defpackage :clack.test
(:use :cl
:cl-test-more)
(:export :test-app
:define-app-test
:*clack-test-handler*
:*clack-test-port*))

(in-package :clack.test)

(defvar *clack-test-handler* 'clack.handler.hunchentoot
"Backend Handler to run tests on. String or Symbol are allowed.")

(defvar *clack-test-port* 8080
"HTTP port number of Handler.")

(defun test-app (desc app client)
"Test Clack Application."
(let* ((handler
(or (find-package *clack-test-handler*)
(error "Handler package is not found. Forgot to load it?: ~A"
*clack-test-handler*)))
(acceptor (funcall (intern "RUN" handler)
app :port *clack-test-port* :debug t)))
(when desc (diag desc))
(unwind-protect
(funcall client)
(funcall (intern "STOP" handler) acceptor))))

(defmacro define-app-test (desc app client)
`(cl-test-more::deftest ,(intern desc)
(test-app nil ,app ,client)))
Loading

0 comments on commit f84dde1

Please sign in to comment.