forked from jscl-project/jscl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.lisp
51 lines (41 loc) · 1.31 KB
/
tests.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(defparameter *total-tests* 0)
(defparameter *passed-tests* 0)
(defparameter *failed-tests* 0)
(defparameter *expected-failures* 0)
(defparameter *unexpected-passes* 0)
(defvar *use-html-output-p* t)
(defvar *timestamp* nil)
(defmacro async (&body body)
`(#j:setTimeout (lambda () ,@body)))
(defun test-fn (condition form)
(async
(cond
(condition
(format t "Test `~S' passed~%" form)
(incf *passed-tests*))
(t
(if *use-html-output-p*
(format t "<font color='red'>Test `~S' failed.</font>~%" form)
(format t "Test `~S' failed.~%" form))
(incf *failed-tests*)))
(incf *total-tests*)))
(defun expected-failure-fn (condition form)
(async
(cond
(condition
(if *use-html-output-p*
(format t "<font color='orange'>Test `~S' passed unexpectedly!</font>~%" 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)
`(test-fn ,condition ',condition))
(defmacro expected-failure (condition)
`(expected-failure-fn ,condition ',condition))
(defmacro test-equal (form value)
`(test (equal ,form, value)))
(setq *timestamp* (get-internal-real-time))
(terpri)