From 07746188cb92ad30b3c86c2598aa0f64ea9ef2ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Fri, 3 May 2013 02:04:54 +0100 Subject: [PATCH] Simplify tests using format --- tests-report.lisp | 25 +++++++------------------ tests.lisp | 26 +++++++++----------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/tests-report.lisp b/tests-report.lisp index 45c7f7c..19a95a7 100644 --- a/tests-report.lisp +++ b/tests-report.lisp @@ -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*)) diff --git a/tests.lisp b/tests.lisp index 65b4ae2..d7d6412 100644 --- a/tests.lisp +++ b/tests.lisp @@ -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 "") - "Test `" - ,(prin1-to-string condition) - "' failed." - (if-html ""))) + (if *use-html-output-p* + (format t "Test `~S' failed.~%" ',condition) + (format t "Test `~S' failed.~%" ',condition)) (incf *failed-tests*))) (incf *total-tests*))) @@ -28,18 +24,14 @@ `(progn (cond (,condition - (write-line (concat (if-html "") - "Test `" - ,(prin1-to-string condition) - "' passed unexpectedly!" - (if-html ""))) + (if *use-html-output-p* + (format t "Test `~S' passed unexpectedly!~%" ',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)) -- 1.7.10.4