Commits

Nikhil Marathe committed 68fbbde

Added macros for assertions to test

Comments (0)

Files changed (1)

 #! /usr/bin/newlisp
+
+(define-macro (assert expr)
+    (let ((assertion-string (join (list "Assertion failed: " (string expr)) "")))
+        (unless (true? (eval expr)) (throw-error assertion-string))))
+
+(define-macro (assert-equals expr val)
+  (letex ((e (eval expr)))
+    (assert (= e val))))
+
+(define-macro (assert-fail expr)
+    (if (nil? (catch (eval expr) 'exc))
+      true ; it failed, just what we wanted
+      (throw-error (append "Should have failed: " (string expr)))))
+
 (load "redis.lsp")
 (setf conn (redis))
 (print (:ping conn))