-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.lisp
60 lines (53 loc) · 2.09 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
52
53
54
55
56
57
58
59
60
(in-package :a-cl-logger)
(cl-interpol:enable-interpol-syntax)
(progn
(define-logger testlog ())
(setf (appenders *testlog*) nil)
(setf (parents *testlog*) nil))
(defun run-tests ()
(unwind-protect
(lisp-unit2:run-tests
:package :a-cl-logger
:name :a-cl-logger
:run-contexts #'lisp-unit2:with-summary-context)))
(lisp-unit2:define-test basic-level-test (:tags '(levels))
(setf (log-level *testlog*) 0)
(iter (for (_0 _1 log-level) in-vector *log-level-names*)
(setf (log-level *testlog*) log-level)
(iter (for (level-name _ message-level) in-vector *log-level-names*)
(if (>= message-level log-level)
(lisp-unit2:assert-signal
'logging-message
(do-log *testlog* message-level "Test ~A" level-name)
message-level
log-level)
(lisp-unit2:assert-no-signal
'logging-message
(do-log *testlog* message-level "Test ~A" level-name)
message-level
log-level)))))
(lisp-unit2:define-test helper-tests (:tags '(helpers))
(setf (level *testlog*) 0)
(lisp-unit2:assert-signal
'logging-message
(handler-bind ((logging-message
(lambda (c) (lisp-unit2:assert-equal +error+ (level (message c))))))
(testlog.error "Test ~A" :some-stuff)))
(lisp-unit2:assert-signal
'logging-message
(handler-bind ((logging-message
(lambda (c) (lisp-unit2:assert-equal +debug+ (level (message c))))))
(testlog.debug "Test ~A" :some-stuff))))
(lisp-unit2:define-test with-appender-test (:tags '(helpers))
(setf (level *testlog*) 0)
(lisp-unit2:assert-eql 0 (length (appenders *testlog*)))
(let ((app (make-instance 'debug-io-log-appender :level +dribble+))
(gotit? nil))
(when-log-message-appended
((when (and (eql *testlog* (logger *message*))
(eql *appender* app))
(setf gotit? t)))
(with-appender (*testlog* app)
(testlog.debug "Test")))
(lisp-unit2:assert-true gotit?))
(lisp-unit2:assert-eql 0 (length (appenders *testlog*))))