From: David Vázquez Date: Thu, 6 Mar 2014 12:04:24 +0000 (+0100) Subject: Run tests asynchronously so it reports incrementally X-Git-Url: http://repo.macrolet.net/gitweb/?p=jscl.git;a=commitdiff_plain;h=cc71efeb9a9b66b650564255b562f0cbdff640fb Run tests asynchronously so it reports incrementally --- 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)