Created
March 5, 2019 00:13
-
-
Save fstamour/a248658b6495cf931fde7658a3a37f30 to your computer and use it in GitHub Desktop.
most minimalistic test library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defparameter *tests* (make-hash-table)) | |
(defun make-test (package body) | |
(list package body)) | |
(defmacro deftest (name &body body) | |
(check-type name symbol) | |
`(setf (gethash ',name *tests*) (make-test *package* '(progn ,@body)))) | |
(defun run-test (name) | |
(destructuring-bind (package body) | |
(gethash name *tests*) | |
(let ((passed nil) | |
(condition nil)) | |
(with-output-to-string (*standard-output*) | |
(handler-case (progn | |
(let ((*package* package)) | |
(eval body)) | |
(setf passed t)) | |
(error (c) (setf condition c)))) | |
(list passed condition)))) | |
(defmacro is (&body body) | |
`(unless (progn ,@body) | |
(error "Expression is falsy: ~A" '(progn ,@body)))) | |
;; This is ok, but it doesn't have a clear report | |
(defun run-all-tests () | |
(loop :for name :being :the :hash-keys :of *tests* | |
:collect (list name (run-test name)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment