(defparameter *unexpected-passes* 0)
(defvar *use-html-output-p* t)
-(defun if-html (string) (if *use-html-output-p* string ""))
-
(defvar *timestamp* nil)
+(defun test-fn (condition form)
+ (cond
+ (condition
+ (format t "Test `~S' passed~%" form)
+ (incf *passed-tests*))
+ (t
+ (if *use-html-output-p*
+ (format t "<font color='red'>Test `~S' failed.</font>~%" form)
+ (format t "Test `~S' failed.~%" form))
+ (incf *failed-tests*)))
+ (incf *total-tests*))
+
+(defun expected-failure-fn (condition form)
+ (cond
+ (condition
+ (if *use-html-output-p*
+ (format t "<font color='orange'>Test `~S' passed unexpectedly!</font>~%" form)
+ (format t "Test `~S' passed unexpectedly!~%" form))
+ (incf *unexpected-passes*))
+ (t
+ (format t "Test `~S' failed expectedly.~%" form)
+ (incf *expected-failures*)))
+ (incf *total-tests*))
+
+
(defmacro test (condition)
- `(progn
- (cond
- (,condition
- (write-line ,(concat "Test `" (prin1-to-string condition) "' passed"))
- (incf *passed-tests*))
- (t
- (write-line (concat (if-html "<font color=red>")
- "Test `"
- ,(prin1-to-string condition)
- "' failed."
- (if-html "</font>")))
- (incf *failed-tests*)))
- (incf *total-tests*)))
+ `(test-fn ,condition ',condition))
(defmacro expected-failure (condition)
- `(progn
- (cond
- (,condition
- (write-line (concat (if-html "<font color=orange>")
- "Test `"
- ,(prin1-to-string condition)
- "' passed unexpectedly!"
- (if-html "</font>")))
- (incf *unexpected-passes*))
- (t
- (write-line ,(concat "Test `" (prin1-to-string condition) "' failed expectedly."))
- (incf *expected-failures*)))
- (incf *total-tests*)))
-
-(write-line "Running tests...")
-(write-line "")
+ `(expected-failure-fn ,condition ',condition))
+
+(defmacro test-equal (form value)
+ `(test (equal ,form, value)))
+(format t "Running tests...~%~%")
(setq *timestamp* (get-internal-real-time))