Coverage report: /home/ellis/comp/core/lib/log/tests.lisp

KindCoveredAll%
expression541 12.2
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 (defpackage :log/tests
2
   (:use :cl :std :rt :log))
3
 
4
 (in-package :log/tests)
5
 
6
 (eval-always
7
   (defclass logger-fixture (logger fixture) ())
8
   (defmethod make-fixture ((kind (eql :logger)) &rest args)
9
     (apply 'make-instance 'logger-fixture args)))
10
 
11
 
12
 (defsuite :log :level :trace)
13
   
14
 (in-suite :log)
15
 
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")))))
22
 
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"))
27
 
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)
33
     (unwind-protect
34
          (with-logger fx
35
            (let ((tmpfile (path tmp)))
36
              ;; (is *logger*)
37
              (log-pipe (make-instance 'file-sink :file tmpfile))
38
              (unless (started-p fx)
39
                (start fx))
40
              (log-message :info '(:file :log) "test")
41
              (sleep 1)
42
              (is> 0 (file-size tmpfile))))
43
       (delete-file (path tmp))))))
44
 
45
 (deftest rotating-file-logger ()
46
   (with-fixture (tmp :tmp :file (tmpize-pathname "log"))
47
     (with-fixture (fx :logger)
48
       (with-logger fx
49
         (let ((tmpfile (path tmp)))
50
           (is *logger*)
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)))))))))
59
 
60
 (deftest simple-log ()
61
   "Test logging features"
62
   (is (debug! "test" *log-level*))
63
   (is (info! "test"))
64
   (is (trace! "test"))
65
   (is (error! "test"))
66
   (is (fatal! "test"))
67
   (is (warn! "test")))
68
 
69
 (deftest stream ()
70
   (let ((str (random-bytes 1024))
71
         (lock (make-mutex))
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*)))
76
     (delete-file *tmp*)))
77
 
78
 (deftest fast-stream ()
79
   (let ((str (random-bytes 1024))
80
         (lock (make-mutex))
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*)))
85
     (delete-file *tmp*)))
86
 
87
 (deftest stop-logger ()
88
   (with-fixture (fx :logger)
89
     (stop fx)))
90
 
91
 (defmethod db:make-db ((engine (eql :faux-log)) &key)
92
   (make-array '(4 100)))
93
 
94
 (defclass faux-db-sink (db-sink) ())
95
 
96
 (defvar *faux-log* (make-instance 'database-logger :db (db:make-db :faux-log)))
97
 
98
 (defun faux-level (int)
99
   (coerce
100
    (loop for i below 100
101
          collect (row-major-aref (db:db *faux-log*) (+ i int)))
102
    'vector))
103
 
104
 (defmethod schema:column ((self faux-db-sink) (col integer)) (faux-level (* 100 col)))
105
 
106
 (deftest database-logger ())
107