Simplify tests using format
authorDavid Vázquez <davazp@gmail.com>
Fri, 3 May 2013 01:04:54 +0000 (02:04 +0100)
committerDavid Vázquez <davazp@gmail.com>
Fri, 3 May 2013 01:04:54 +0000 (02:04 +0100)
tests-report.lisp
tests.lisp

index 45c7f7c..19a95a7 100644 (file)
@@ -1,23 +1,12 @@
-(write-line "")
-(write-string "Finished. The execution took ")
-(write-string (prin1-to-string (/ (- (get-internal-real-time) *timestamp*) internal-time-units-per-second 1.0)))
-(write-line " seconds.")
+(format t "~%Finished. The execution took ~a seconds.~%"
+        (/ (- (get-internal-real-time) *timestamp*) internal-time-units-per-second 1.0))
 
-(cond
-  ((= *passed-tests* *total-tests*)
-   (write-line "All the tests (")
-   (write-string (prin1-to-string *total-tests*))
-   (write-line ") passed successfully."))
-  (t
-   (write-string (prin1-to-string *passed-tests*))
-   (write-string "/")
-   (write-string (prin1-to-string *total-tests*))
-   (write-line " test(s) passed successfully.")))
+(if (= *passed-tests* *total-tests*)
+    (format t "All the tests (~a) passed successfully.~%" *total-tests*)
+    (format t "~a/~a test(s) passed successfully.~%" *passed-tests* *total-tests*))
 
 (unless (zerop *expected-failures*)
-  (write-string (prin1-to-string *expected-failures*))
-  (write-line " test(s) failed expectedly."))
+  (format t "~a test(s) failed expectedly.~%" *expected-failures*))
 
 (unless (zerop *unexpected-passes*)
-  (write-string (prin1-to-string *unexpected-passes*))
-  (write-line " test(s) passed unexpectedly."))
+  (format t "~a test(s) passed unexpectedly.~%" *unexpected-passes*))
index 65b4ae2..d7d6412 100644 (file)
@@ -5,22 +5,18 @@
 (defparameter *unexpected-passes* 0)
 
 (defvar *use-html-output-p* t)
-(defun if-html (string) (if *use-html-output-p* string ""))
-
 (defvar *timestamp* nil)
 
 (defmacro test (condition)
   `(progn
      (cond
        (,condition
-        (write-line ,(concat "Test `" (prin1-to-string condition) "' passed"))
+        (format t "Test `~S' passed~%" ',condition)
         (incf *passed-tests*))
        (t
-        (write-line (concat (if-html "<font color=red>")
-                            "Test `"
-                            ,(prin1-to-string condition) 
-                            "' failed."
-                            (if-html "</font>")))
+        (if *use-html-output-p*
+            (format t "<font color='red'>Test `~S' failed.</font>~%" ',condition)
+            (format t "Test `~S' failed.~%" ',condition))
         (incf *failed-tests*)))
      (incf *total-tests*)))
 
   `(progn
      (cond
        (,condition
-         (write-line (concat (if-html "<font color=orange>")
-                             "Test `"
-                             ,(prin1-to-string condition)
-                             "' passed unexpectedly!"
-                             (if-html "</font>")))
+        (if *use-html-output-p*
+            (format t "<font color='orange'>Test `~S' passed unexpectedly!</font>~%" ',condition)
+            (format t "Test `~S' passed unexpectedly!~%" ',condition))
         (incf *unexpected-passes*))
        (t
-        (write-line ,(concat "Test `" (prin1-to-string condition) "' failed expectedly."))
+        (format t "Test `~S' failed failed expectedly.~%" ',condition)
         (incf *expected-failures*)))
      (incf *total-tests*)))
 
-(write-line "Running tests...")
-(write-line "")
-
+(format t "Running tests...~%~%")
 (setq *timestamp* (get-internal-real-time))