From cc71efeb9a9b66b650564255b562f0cbdff640fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Thu, 6 Mar 2014 13:04:24 +0100 Subject: [PATCH] Run tests asynchronously so it reports incrementally --- tests-report.lisp | 23 +++++++++++++---------- tests.lisp | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/tests-report.lisp b/tests-report.lisp index 1b44496..3725787 100644 --- a/tests-report.lisp +++ b/tests-report.lisp @@ -1,14 +1,17 @@ -(format t "~%Finished. The execution took ~a seconds.~%" - (/ (- (get-internal-real-time) *timestamp*) internal-time-units-per-second 1.0)) +(async + (format t "~%Finished. The execution took ~a seconds.~%" + (/ (- (get-internal-real-time) *timestamp*) internal-time-units-per-second 1.0)) -(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*)) + (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*) - (format t "~a test(s) failed expectedly.~%" *expected-failures*)) + (unless (zerop *expected-failures*) + (format t "~a test(s) failed expectedly.~%" *expected-failures*)) -(unless (zerop *unexpected-passes*) - (format t "~a test(s) passed unexpectedly.~%" *unexpected-passes*)) + (unless (zerop *unexpected-passes*) + (format t "~a test(s) passed unexpectedly.~%" *unexpected-passes*)) -(terpri) + (terpri) + + (init)) diff --git a/tests.lisp b/tests.lisp index 1eca341..5559d38 100644 --- a/tests.lisp +++ b/tests.lisp @@ -7,29 +7,34 @@ (defvar *use-html-output-p* t) (defvar *timestamp* nil) +(defmacro async (&body body) + `(#j:setTimeout (lambda () ,@body))) + (defun test-fn (condition form) - (cond - (condition - (format t "Test `~S' passed~%" form) - (incf *passed-tests*)) - (t - (if *use-html-output-p* - (format t "Test `~S' failed.~%" form) - (format t "Test `~S' failed.~%" form)) - (incf *failed-tests*))) - (incf *total-tests*)) + (async + (cond + (condition + (format t "Test `~S' passed~%" form) + (incf *passed-tests*)) + (t + (if *use-html-output-p* + (format t "Test `~S' failed.~%" 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 "Test `~S' passed unexpectedly!~%" 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*)) + (async + (cond + (condition + (if *use-html-output-p* + (format t "Test `~S' passed unexpectedly!~%" 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) -- 1.7.10.4