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