Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
91 lines (74 sloc) 2.36 KB
This file is a part of Clack package.
Copyright (c) 2011 Eitarow Fukamachi <>
Clack is freely distributable under the LLGPL License.
(clack.util:namespace clack.test
(:use :cl)
(:import-from :cl-test-more
(:import-from :clack.util
(cl-syntax:use-syntax :annot)
(defvar *clack-test-handler* :hunchentoot
"Backend Handler to run tests on. String or Symbol are allowed.")
(defvar *clack-test-port* 4242
"HTTP port number of Handler.")
(defvar *enable-debug-p* t)
(defun test-app (app client &optional desc)
"Test Clack Application."
(let* ((handler (find-handler *clack-test-handler*))
(acceptor (funcall (intern (string '#:run) handler)
:port *clack-test-port*
:debug *enable-debug-p*)))
(when desc (diag desc))
(funcall client)
(funcall (intern (string '#:stop) handler) acceptor))))
(defmacro define-app-test (desc app client &optional (enable-debug-p *enable-debug-p*))
"Define tests for Clack Application. This just wrap `cl-test-more:deftest', so you can run this test by calling `(cl-test-more:run-test :foo)'."
`(deftest ,desc
(let ((*enable-debug-p* ,enable-debug-p))
(test-app ,app ,client))))
@doc:NAME "
Clack.Test - Testing Clack Applications.
(defpackage clack-test.sample
(:use :cl
(in-package :clack-test.sample)
(lambda (env)
(declare (ignore env))
`(200 (:content-type \"text/plain\") (\"Hello, Clack!\")))
(lambda ()
(multiple-value-bind (body status headers)
(http-request \"http://localhost:4242\")
(is status 200)
(is body \"Hello, Clack!\")
(is (assoc :content-type headers) \"text/plain\")))
\"Testing simple application\")
Clack.Test provides simple interface to test Clack Application or Middleware.
Your Lisp have to support multi-thread to run this.
@doc:AUTHOR "
Eitarow Fukamachi (
@doc:SEE "
* Drakma
Jump to Line
Something went wrong with that request. Please try again.