Skip to content

Instantly share code, notes, and snippets.

@ideal-knee
Created May 29, 2016 04:24
Show Gist options
  • Save ideal-knee/92937e5ec017e2890a01f75055f4f8e4 to your computer and use it in GitHub Desktop.
Save ideal-knee/92937e5ec017e2890a01f75055f4f8e4 to your computer and use it in GitHub Desktop.
(defmacro should-equal (a b)
(let ((a-sym (gensym))
(b-sym (gensym)) )
`(let ((,a-sym ,a)
(,b-sym ,b) )
(if (not (equal ,a-sym ,b-sym))
(push (format nil "~a is not equal to ~a" ,a-sym ,b-sym) *results*) ) ) ) )
(defmacro context (description &rest body)
`(let ((indent (if (boundp '*indent*)
*indent*
"" )))
(format t "~a~a~%" indent ,description)
(let ((*indent* (concatenate 'string indent " ")))
(declare (special *indent*))
,@body ) ) )
(defmacro test-that-it (description &rest body)
`(let ((*results* nil)
(indent (if (boundp '*indent*)
*indent*
"" )) )
(format t "~ait ~a" indent ,description)
,@body
(if *results*
(progn
(format t " *FAILED*~%")
(format t (format nil "~~{~a -> ~~a~~%~~}" indent) *results*) )
(format t "~%") ) ) )
(context "meta-testing"
(context "passing specs"
(test-that-it "prints success message if all assertions are met"
(let ((x 1)
(y 2) )
(should-equal x 1)
(should-equal y 2) ) ))
(context "faiing specs"
(test-that-it "prints failure messages if assertions are not met"
(let ((x 1)
(y 2) )
(should-equal x 2)
(should-equal y 1) ) )) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment