Use defparameter instead of defvar to reset test reporting data
[jscl.git] / tests.lisp
1 (defparameter *total-tests* 0)
2 (defparameter *passed-tests* 0)
3 (defparameter *failed-tests* 0)
4 (defparameter *expected-failures* 0)
5 (defparameter *unexpected-passes* 0)
6
7 (defvar *use-html-output-p* t)
8 (defun if-html (string) (if *use-html-output-p* string ""))
9
10 (defvar *timestamp* nil)
11
12 (defmacro test (condition)
13   `(progn
14      (cond
15        (,condition
16         (write-line ,(concat "Test `" (prin1-to-string condition) "' passed"))
17         (incf *passed-tests*))
18        (t
19         (write-line (concat (if-html "<font color=red>")
20                             "Test `"
21                             ,(prin1-to-string condition) 
22                             "' failed."
23                             (if-html "</font>")))
24         (incf *failed-tests*)))
25      (incf *total-tests*)))
26
27 (defmacro expected-failure (condition)
28   `(progn
29      (cond
30        (,condition
31          (write-line (concat (if-html "<font color=orange>")
32                              "Test `"
33                              ,(prin1-to-string condition)
34                              "' passed unexpectedly!"
35                              (if-html "</font>")))
36         (incf *unexpected-passes*))
37        (t
38         (write-line ,(concat "Test `" (prin1-to-string condition) "' failed expectedly."))
39         (incf *expected-failures*)))
40      (incf *total-tests*)))
41
42 (write-line "Running tests...")
43 (write-line "")
44
45 (setq *timestamp* (get-internal-real-time))