Skip to content

Commit

Permalink
[ colored tests ]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Rothstein committed Feb 21, 2011
1 parent 9488112 commit f5e3c38
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions test/testHelper.sib
Expand Up @@ -8,22 +8,29 @@

(console.log (concat "Testing " (sibilant.version-string)))

(defun green (&rest args)
(concat "\033[32m" (join "" args) "\033[0m"))

(defun red (&rest args)
(concat "\033[31m" (join "" args) "\033[0m"))

(defun trim (string)
(if string (string.trim) ""))

(defun assert (thing &optional message)
(sys.print (if thing
(progn (incr passes) ".")
(progn (incr passes) (green "."))
(progn (incr fails)
(concat "F\n\n" (+ passes fails) ": "
(concat (red "F") "\n" (+ passes fails) ": "
(or message "")
(get (new (Error)) 'stack))))))
(get (new (Error)) 'stack)
"\n")))))

(defun assert-equal (expected actual &optional message)
(assert (= expected actual)
(concat (if message (concat message "\n\n") "")
(concat (if message (concat message "\n") "")
"expected " (inspect expected)
"\n\nbut got " (inspect actual) "\n\n")))
"\n but got " (inspect actual) "\n\n")))

(defun assert-match (regex thing &optional message)
(assert (regex.test thing)
Expand All @@ -49,5 +56,5 @@
(assert-equal item (get actual index))))

(process.next-tick (lambda ()
(console.log (concat "\n\n" (+ passes fails) " total tests, "
passes " passed, " fails " failed"))))
(console.log (concat "\n\n" (+ passes fails) " total tests, "
(green passes " passed") ", " (red fails " failed")))))

0 comments on commit f5e3c38

Please sign in to comment.