Writing a Barebones Test Library
Here’s my latest experiment with Common Lisp, trying to write a small library for testing simple predicates. It runs a series of tests and report whether each test passed or failed, with a short summary at the end,
(defmacro make-test (name predicate) `(lambda () (let ((p ,predicate)) (if p (format t "Test `~A` passed~%" ,name) (format t "Test `~A` failed~%" ,name)) p))) (defun run-tests (&rest tests) (let* ((score (lambda (p) (if p 1 0))) (run-test (lambda (test) (funcall test))) (scores (map 'list score (map 'list run-test tests))) (num-tests (length scores)) (num-passes (reduce #'+ scores))) (format t "~A out of ~A tests passed~%" num-passes num-tests))) To use it I do the following,
Read more...