67 lines
1.8 KiB
Common Lisp
67 lines
1.8 KiB
Common Lisp
;;;; cl-scopes/testing
|
|
|
|
;;;; simple testing library
|
|
|
|
(defpackage :scopes/testing
|
|
(:use :common-lisp)
|
|
(:export #:*test-suite*
|
|
#:test-suite #:deftest #:show-result
|
|
#:failure #:check #:test #:== #:has-prefix
|
|
#:test-path #:*current-system*))
|
|
|
|
(in-package :scopes/testing)
|
|
|
|
(defvar *test-suite* nil)
|
|
(defparameter *current-system* :scopes)
|
|
|
|
(defclass test-suite ()
|
|
((name :reader name :initform "test" :initarg :name)
|
|
(errors :accessor errors :initform nil)
|
|
(result :accessor result :initform nil)))
|
|
|
|
(defun test-suite (&optional (name "test"))
|
|
(make-instance 'test-suite :name name))
|
|
|
|
(defun show-result ()
|
|
(let ((suite *test-suite*))
|
|
(format t "~%=== ~a Tests ===~%" (name suite) )
|
|
(dolist (res (reverse (result suite)))
|
|
(let ((tst (reverse res)))
|
|
(format t "~a: ~a~%" (car tst) (cdr tst))))
|
|
(if (errors suite)
|
|
(format t "*** errors: ~a~%" (reverse (errors suite)))))
|
|
(values))
|
|
|
|
(defun failure (fmt &rest vals)
|
|
(push (apply #'format nil fmt vals) (errors *test-suite*)))
|
|
|
|
(defun check (fn fmt have wanted)
|
|
(let ((is-ok (funcall fn have wanted)))
|
|
(push is-ok (car (result *test-suite*)))
|
|
(unless is-ok
|
|
(failure fmt have wanted))))
|
|
|
|
(defun == (have wanted)
|
|
(check #'equalp "~s!=~s" have wanted))
|
|
|
|
(defun != (have wanted)
|
|
(check #'(lambda (h w) (not (equalp h w))) "~s==~s" have wanted))
|
|
|
|
(defun has-prefix (have wanted)
|
|
(check #'(lambda (h w) (string= (str:prefix (list h w)) w))
|
|
"~s has not prefix ~s" have wanted))
|
|
|
|
(defmacro deftest (name args &body body)
|
|
`(defun ,name ,args
|
|
(push '(,name) (result *test-suite*))
|
|
,@body))
|
|
|
|
;;;; utilities
|
|
|
|
(defmacro normalize (&rest xs)
|
|
)
|
|
|
|
(defun test-path (name &rest dirs)
|
|
(apply #'scopes/util:system-path *current-system* name "test" dirs))
|
|
|
|
|