| 1 |
;; |
| 2 |
;; testing gauche.logger |
| 3 |
;; |
| 4 |
|
| 5 |
(use gauche.test) |
| 6 |
|
| 7 |
;; NB: logger uses gauche.fcntl. Before 'make link', it can't be |
| 8 |
;; loaded by 'use'. |
| 9 |
(when (file-exists? "../ext/fcntl/fcntl.scm") |
| 10 |
(add-load-path "../ext/fcntl") |
| 11 |
(load "../ext/fcntl/fcntl")) |
| 12 |
(when (file-exists? "../ext/syslog/syslog.scm") |
| 13 |
(add-load-path "../ext/syslog") |
| 14 |
(load "../ext/syslog/syslog")) |
| 15 |
(test-start "logger") |
| 16 |
(use gauche.logger) |
| 17 |
(test-module 'gauche.logger) |
| 18 |
|
| 19 |
;;------------------------------------------------------------------------- |
| 20 |
(test-section "log-open") |
| 21 |
|
| 22 |
(sys-system "rm -f test.o") |
| 23 |
|
| 24 |
;; these shouldn't go to the log |
| 25 |
(log-format "testing...") |
| 26 |
(log-format "testing ~a..." 2) |
| 27 |
(log-format "testing ~a..." 3) |
| 28 |
|
| 29 |
(log-open "test.o") |
| 30 |
|
| 31 |
(log-format "real testing...") |
| 32 |
(log-format "real testing ~a..." 2) |
| 33 |
(log-format "output string\ncontaining newline\ncharacters") |
| 34 |
|
| 35 |
(log-open #f) |
| 36 |
|
| 37 |
(log-format "fake testing...") |
| 38 |
|
| 39 |
(log-open "test.o") |
| 40 |
|
| 41 |
(log-format "real testing again...") |
| 42 |
|
| 43 |
(test "log-open" |
| 44 |
'("real testing..." |
| 45 |
"real testing 2..." |
| 46 |
"output string" |
| 47 |
"containing newline" |
| 48 |
"characters" |
| 49 |
"real testing again...") |
| 50 |
(lambda () |
| 51 |
(map (lambda (line) |
| 52 |
(cond ((#/^... .. ..:..:.. .+\[\d+\]: (.*)$/ line) |
| 53 |
=> (^m (m 1))) |
| 54 |
(else #f))) |
| 55 |
(call-with-input-file "test.o" port->string-list)))) |
| 56 |
|
| 57 |
(sys-system "rm -f test.o") |
| 58 |
|
| 59 |
;;------------------------------------------------------------------------- |
| 60 |
(test-section "customized formatter") |
| 61 |
|
| 62 |
(sys-system "rm -f test.o") |
| 63 |
|
| 64 |
(log-open "test.o" :prefix "zeepa:") |
| 65 |
(log-format "booba bunba bomba") |
| 66 |
|
| 67 |
(test "customized formatter" |
| 68 |
'("zeepa:booba bunba bomba") |
| 69 |
(lambda () |
| 70 |
(call-with-input-file "test.o" port->string-list))) |
| 71 |
|
| 72 |
(sys-system "rm -f test.o") |
| 73 |
|
| 74 |
(log-open "test.o" :prefix (lambda (drain) "poopa:")) |
| 75 |
(log-format "booba bunba bomba") |
| 76 |
|
| 77 |
(test "customized formatter" |
| 78 |
'("poopa:booba bunba bomba") |
| 79 |
(lambda () |
| 80 |
(call-with-input-file "test.o" port->string-list))) |
| 81 |
|
| 82 |
(test-end) |