diff options
author | Daniel Santos <dacs.git@brilhante.top> | 2023-02-25 16:11:59 +0000 |
---|---|---|
committer | Daniel Santos <dacs.git@brilhante.top> | 2023-02-25 16:11:59 +0000 |
commit | 737859a9a6ef329b64468800f3513de72b749018 (patch) | |
tree | 937717f33ab4c2578ba29d22b386c4bd0b284580 /test.lisp | |
parent | 0bf691a809be13901c62b5d78bed742bdb3161c9 (diff) | |
download | cl-math-737859a9a6ef329b64468800f3513de72b749018.tar.gz |
add testing files
Diffstat (limited to 'test.lisp')
-rw-r--r-- | test.lisp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test.lisp b/test.lisp new file mode 100644 index 0000000..5f65ccc --- /dev/null +++ b/test.lisp @@ -0,0 +1,31 @@ +;(in-package :test) + +(defvar *test-name* nil) + +(defmacro with-gensyms ((&rest names) &body body) + `(let ,(loop for n in names collect `(,n (gensym))) + ,@body)) + +(defmacro deftest (name parameters &body body) + "Define a test function. Within a test function we can call other +test functions or use `check' to run individual test cases." + `(defun ,name ,parameters + (let ((*test-name* (append *test-name* (list ',name)))) + ,@body))) + +(defmacro check (&body forms) + "Run each expression in `forms' as a test case." + `(combine-results + ,@(loop for f in forms collect `(report-result ,f ',f)))) + +(defmacro combine-results (&body forms) + "Combine the results (as booleans) of evaluating `forms' in order." + (with-gensyms (result) + `(let ((,result t)) + ,@(loop for f in forms collect `(unless ,f (setf ,result nil))) + ,result))) + +(defun report-result (result form) + "Report the results of a single test case. Called by `check'." + (format t "~:[FAIL~;pass~] ... ~a: ~a~%" result *test-name* form) + result) |