1. Nikhil Marathe
  2. newlisp-redis


newlisp-redis / test-redis.lsp

#! /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))

(assert-equals (:select conn 14) "OK")

;; If you have authentication enabled
;; uncomment this
;; (assert-equals (:auth conn "foobared") "OK")

(assert-equals (:ping conn) "PONG")
(assert-equals (:bgsave conn) "Background saving started")

(assert (true? (:get conn "minestrone:song:8412c5ea08987a59ca7e1a9e0651cdb4af4bfe9f")))

(println "Database size is " (:dbsize conn))

(:close conn)

;(assert-fail (:get conn "minestrone:playlist:sXLruRrkPApP3eErshhqtE"))