File: loggerUtils.test

package info (click to toggle)
tcllib 1.19-dfsg-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 67,328 kB
  • sloc: tcl: 208,371; ansic: 14,215; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 583; makefile: 106; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (224 lines) | stat: -rw-r--r-- 5,513 bytes parent folder | download | duplicates (6)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# -*- tcl -*-
# Tests for the utilities to the logger facility.
#
# Sourcing this file into Tcl runs the tests and generates output for errors.
# No output means no errors were found.
#
# Copyright (c) 2005 by Aamer Aahkter
#
# $Id: loggerUtils.test,v 1.7 2006/10/09 21:41:41 andreas_kupries Exp $

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.4
testsNeedTcltest 2.2

support {
    useLocal logger.tcl         logger
    useLocal loggerAppender.tcl logger::appender
}
testing {
    useLocal loggerUtils.tcl logger::utils
}

# -------------------------------------------------------------------------

logger::setlevel debug

# -------------------------------------------------------------------------

namespace eval ::loggerExtension::test {

    ::tcltest::test load {} -setup {
    } -constraints {
    } -cleanup {
    } -body {
    } -returnCodes {
        ok
    } -result {}


    ::tcltest::test createFormatCmd-1 {
    check for %d
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    set a [logger::utils::createFormatCmd %d]
    set b [subst $a]
    regexp {\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d} $b
    } -result {1}

    ::tcltest::test createFormatCmd-2 {
    check for %P
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    set a [logger::utils::createFormatCmd %P]
    set b [subst $a]
    } -returnCodes {
        ok
    } -result [pid]

    ::tcltest::test createFormatCmd-3 {
    check for %H
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    set a [logger::utils::createFormatCmd %H]
    set b [subst $a]
    } -returnCodes {
        ok
    } -result [info hostname]

    ::tcltest::test createFormatCmd-4 {
    check for %c
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    set a [logger::utils::createFormatCmd %c -category test::cat ] 
    set b [subst $a]
    } -returnCodes {
        ok
    } -result test::cat

    ::tcltest::test createFormatCmd-5 {
    check for %C
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    set a [logger::utils::createFormatCmd %C -category test::cat ] 
    set b [subst $a]
    } -returnCodes {
        ok
    } -result test

    ::tcltest::test createFormatCmd-6 {
    check for %p
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    set a [logger::utils::createFormatCmd %p -category test::cat -priority error] 
    set b [subst $a]
    } -returnCodes {
        ok
    } -result error


    ::tcltest::test createLogProc-1 {
    create a proc and test it
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    set a [logger::utils::createLogProc \
           -category catTest \
           -priority critical \
           -procName ::bobo \
           -conversionPattern {\[%d\] \[%c\] \[%M\] \[%p\] %m}]
    eval $a
    ::bobo test
    } -returnCodes {ls

    ok
    }  -match regexp \
    -output {\[[\d:\/ ]+\] \[catTest\] \[namespace\] \[critical\] test}

    ::tcltest::test applyAppender-1 {
    apply an appender 
    } -setup {
    } -constraints {
    } -cleanup {
    ${log}::delete
    unset log
    } -body {
    set log [logger::init testLog]
    logger::utils::applyAppender -appender console -serviceCmd $log
    ${log}::error "this is error"
    } -returnCodes {
        ok
    }  -match regexp \
    -output {\[[\d:\/ ]+\] \[testLog\] \[namespace\] \[error\] this is error}

    ::tcltest::test applyAppender-2 {
    apply an appender, to 2 loggers
    } -setup {
    } -constraints {
    } -cleanup {
    ${log1}::delete
    ${log2}::delete
    unset log1
    unset log2
    } -body {
    set log1 [logger::init testLog1]
    set log2 [logger::init testLog2]
    logger::utils::applyAppender -appender console -serviceCmd [list $log1 $log2]
    ${log1}::error "this is error1"
    ${log2}::error "this is error2"
    } -returnCodes {
        ok
    }  -match regexp \
    -output {\[[\d:\/ ]+\] \[testLog1\] \[namespace\] \[error\] this is error1\n\[[\d:\/ ]+\] \[testLog2\] \[namespace\] \[error\] this is error2}


    ::tcltest::test applyAppender-3 {
    auto apply
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    logger::utils::applyAppender -appender console
    set log [logger::init applyAppender-3]
    ${log}::error "this is error"
    } -returnCodes {
        ok
    } -match regexp \
    -output {\[[\d:\/ ]+\] \[applyAppender-3\] \[namespace\] \[error\] this is error}

    ::tcltest::test applyAppender-4 {
    auto apply
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    logger::utils::applyAppender -appender colorConsole
    set log [logger::init applyAppender-4]
    ${log}::error "this is error"
    } -returnCodes {
        ok
    } -match regexp \
    -output {\[[\d:\/ ]+\] \[applyAppender-4\] \[namespace\] \[error\] this is error}

    ::tcltest::test applyAppender-5 {
    auto apply fileAppend
    } -setup {
    } -constraints {
    } -cleanup {
    } -body {
    logger::utils::applyAppender \
        -appender fileAppend -appenderArgs {-outputChannel stderr}
    set log [logger::init applyAppender-5]
    ${log}::error "this is error"
    } -returnCodes {
    ok
    } -match regexp \
    -errorOutput {\[[\d:\/ ]+\] \[applyAppender-5\] \[namespace\] \[error\] this is error}
    

}


testsuiteCleanup

# ;;; Local Variables: ***
# ;;; mode: tcl ***
# ;;; End: ***