From 127aa16e32db3de4dab2864ec31149cef48ac0ae Mon Sep 17 00:00:00 2001 From: Eitaro Fukamachi Date: Sun, 22 Mar 2015 22:13:09 +0900 Subject: [PATCH] Add tests of lack-util. --- lack-util.asd | 3 ++- t-lack-util.asd | 17 +++++++++++++++++ t/util.lisp | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 t-lack-util.asd create mode 100644 t/util.lisp diff --git a/lack-util.asd b/lack-util.asd index b8a299f..1e93e17 100644 --- a/lack-util.asd +++ b/lack-util.asd @@ -9,4 +9,5 @@ :license "LLGPL" :depends-on (:ironclad :alexandria) - :components ((:file "src/util"))) + :components ((:file "src/util")) + :in-order-to ((test-op (test-op t-lack-util)))) diff --git a/t-lack-util.asd b/t-lack-util.asd new file mode 100644 index 0000000..9b5763f --- /dev/null +++ b/t-lack-util.asd @@ -0,0 +1,17 @@ +(in-package :cl-user) +(defpackage t-lack-util-asd + (:use :cl :asdf)) +(in-package :t-lack-util-asd) + +(defsystem t-lack-util + :author "Eitaro Fukamachi" + :license "LLGPL" + :depends-on (:lack-test + :lack-util + :prove) + :components + ((:test-file "t/util")) + + :defsystem-depends-on (:prove-asdf) + :perform (test-op :after (op c) + (funcall (intern #.(string :run-test-system) :prove) c))) diff --git a/t/util.lisp b/t/util.lisp new file mode 100644 index 0000000..5f308d3 --- /dev/null +++ b/t/util.lisp @@ -0,0 +1,42 @@ +(in-package :cl-user) +(defpackage t.lack.util + (:use :cl + :prove + :lack.util + :lack.test)) +(in-package :t.lack.util) + +(plan 2) + +(subtest "find-package-or-load" + (is (find-package-or-load "LACK") + (find-package :lack)) + (is (find-package-or-load "hoge") nil)) + +(subtest "funcall-with-cb" + (let ((cb (lambda (res) + (rplacd (car (last res)) (list "(ok from cb)")) + res))) + ;; cons + (let ((app (lambda (env) + (declare (ignore env)) + '(200 (:content-type "text/plain") ("ok"))))) + (is (funcall-with-cb app (generate-env "/") cb) + '(200 (:content-type "text/plain") ("ok" "(ok from cb)")))) + ;; function + (let* ((app (lambda (env) + (declare (ignore env)) + (lambda (responder) + (funcall responder '(200 (:content-type "text/plain") ("ok")))))) + (cb-res (funcall-with-cb app (generate-env "/") cb))) + (is-type cb-res 'function) + (let (res) + (funcall cb-res (lambda (r) (setf res r))) + (is res '(200 (:content-type "text/plain") ("ok" "(ok from cb)"))))) + ;; otherwise + (let ((app (lambda (env) + (declare (ignore env)) + 1))) + (is (funcall-with-cb app (generate-env "/") cb) 1)))) + +(finalize)