Coverage report: /home/ellis/comp/core/lib/log/tests.lisp
Kind | Covered | All | % |
expression | 5 | 41 | 12.2 |
branch | 0 | 0 | nil |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
2
(:use :cl :std :rt :log))
4
(in-package :log/tests)
7
(defclass logger-fixture (logger fixture) ())
8
(defmethod make-fixture ((kind (eql :logger)) &rest args)
9
(apply 'make-instance 'logger-fixture args)))
12
(defsuite :log :level :trace)
16
(deftest simple-log-message ()
17
"Test a simple LOG-MESSAGE"
18
(with-fixture (fx :logger)
19
(istype 'string (format-message nil (make-instance 'simple-log-message :content "hi" :tags '(:test))))
20
(istype 'thread (start fx))
21
(istype 'string (format-message nil (log-message :error nil "test")))))
23
(deftest simple-logger (:fx :logger)
24
"Test a simple LOGGER."
25
(issubclass 'pipe (class-of *fx*))
26
(log-message :info '(:foo :bar) "this is a test"))
28
;; TODO 2024-10-29: fix file loggers
29
(deftest file-logger ()
30
"Test a file-backed LOGGER."
31
(with-fixture (tmp :tmp :file (tmpize-pathname "test.log"))
32
(with-fixture (fx :logger)
35
(let ((tmpfile (path tmp)))
37
(log-pipe (make-instance 'file-sink :file tmpfile))
38
(unless (started-p fx)
40
(log-message :info '(:file :log) "test")
42
(is> 0 (file-size tmpfile))))
43
(delete-file (path tmp))))))
45
(deftest rotating-file-logger ()
46
(with-fixture (tmp :tmp :file (tmpize-pathname "log"))
47
(with-fixture (fx :logger)
49
(let ((tmpfile (path tmp)))
51
(setf (pipe *logger*) (make-pipe))
52
(log-pipe (make-instance 'rotating-file-sink :path tmpfile))
53
(is (probe-file (file (aref (aref (pipe *logger*) 0) 0))))
54
(log-message :info nil "rotating log test")
55
(log-rotate (aref (aref (pipe *logger*) 0) 0))
56
(log-message :info nil "rotating test2")
57
(is> 0 (file-size (print (file (aref (aref (pipe *logger*) 0) 0)))))
58
(is (delete-file (file (aref (aref (pipe *logger*) 0) 0)))))))))
60
(deftest simple-log ()
61
"Test logging features"
62
(is (debug! "test" *log-level*))
70
(let ((str (random-bytes 1024))
72
(*tmp* (tmpize-pathname "/tmp/log-stream")))
73
(with-log-stream (st *tmp* lock)
74
(write-sequence str st))
75
(is (= (length str) (file-size *tmp*)))
78
(deftest fast-stream ()
79
(let ((str (random-bytes 1024))
81
(*tmp* (tmpize-pathname "/tmp/fast-log-stream")))
82
(with-fast-log-stream (st *tmp* lock)
83
(io/fast:fast-write-sequence str st))
84
(is (= (length str) (file-size *tmp*)))
87
(deftest stop-logger ()
88
(with-fixture (fx :logger)
91
(defmethod db:make-db ((engine (eql :faux-log)) &key)
92
(make-array '(4 100)))
94
(defclass faux-db-sink (db-sink) ())
96
(defvar *faux-log* (make-instance 'database-logger :db (db:make-db :faux-log)))
98
(defun faux-level (int)
100
(loop for i below 100
101
collect (row-major-aref (db:db *faux-log*) (+ i int)))
104
(defmethod schema:column ((self faux-db-sink) (col integer)) (faux-level (* 100 col)))
106
(deftest database-logger ())