forked from rokudev/unit-testing-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfw_logger.brs
217 lines (182 loc) · 7.22 KB
/
fw_logger.brs
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
'*****************************************************************
'* Copyright Roku 2011-2016
'* All Rights Reserved
'*****************************************************************
' Functions in this file:
' Logger
' Logger__Run
'----------------------------------------------------------------
' Main function. Create Logger object.
'
' @return A Logger object.
'----------------------------------------------------------------
Function Logger() as Object
this = {}
this.verbosityLevel = {
basic : 0
normal : 1
verbose : 2
}
' Internal properties
this.verbosity = 1
this.serverURL = invalid
' Interface
this.setVerbosity = Logger__SetVerbosity
this.setServerURL = Logger__SetServerURL
this.printStatistic = Logger__PrintStatistic
this.sendToServer = Logger__SendToServer
' Internal functions
this.printSuiteStatistic = Logger__PrintSuiteStatistic
this.printTestStatistic = Logger__PrintTestStatistic
this.printStart = Logger__PrintStart
this.printEnd = Logger__PrintEnd
this.printSuiteStart = Logger__PrintSuiteStart
this.printSuiteEnd = Logger__PrintSuiteEnd
this.printTestStart = Logger__PrintTestStart
this.printTestEnd = Logger__PrintTestEnd
return this
End Function
'----------------------------------------------------------------
' Set logging verbosity parameter.
'
' @param verbosity (integer) A verbosity level.
' Posible values:
' 0 - basic
' 1 - normal
' 2 - verbose
' Default level: 1
'----------------------------------------------------------------
Sub Logger__SetVerbosity(verbosity = 1 as integer)
if verbosity >= 0 and verbosity <= 2
m.verbosity = verbosity
end if
End Sub
'----------------------------------------------------------------
' Set storage server URL parameter.
'
' @param url (string) A storage server URL.
' Default level: invalid
'----------------------------------------------------------------
Sub Logger__SetServerURL(url = invalid as string)
if url <> invalid
m.serverURL = url
end if
End Sub
'----------------------------------------------------------------
' Set storage server URL parameter.
'
' @param url (string) A storage server URL.
' Default level: invalid
'----------------------------------------------------------------
Sub Logger__SendToServer(statObj as object)
if m.serverURL <> invalid
' Send log file to server
end if
End Sub
'----------------------------------------------------------------
' Print statistic object with specified verbosity.
'
' @param statObj (object) A statistic object to print.
'----------------------------------------------------------------
Sub Logger__PrintStatistic(statObj as object)
m.printStart()
if m.verbosity = m.verbosityLevel.normal
for each testSuite in statObj.Suites
for each testCase in testSuite.Tests
? "*** "; testSuite.Name; ": "; testCase.Name; " - "; testCase.Result
end for
end for
else if m.verbosity = m.verbosityLevel.verbose
for each testSuite in statObj.Suites
m.printSuiteStatistic(testSuite)
end for
end if
? "***"
? "*** Total = "; FW_AsString(statObj.Total); " ; Passed = "; statObj.Correct; " ; Failed = "; statObj.Fail; " ; Crashes = "; statObj.Crash;
? " Time spent: "; statObj.Time; "ms"
? "***"
m.printEnd()
End Sub
'----------------------------------------------------------------
' Print test suite statistic.
'
' @param statSuiteObj (object) A target test suite object to print.
'----------------------------------------------------------------
Sub Logger__PrintSuiteStatistic(statSuiteObj as object)
m.printSuiteStart(statSuiteObj.Name)
for each testCase in statSuiteObj.Tests
m.printTestStatistic(testCase)
end for
? "==="
? "=== Total = "; FW_AsString(statSuiteObj.Total); " ; Passed = "; statSuiteObj.Correct; " ; Failed = "; statSuiteObj.Fail; " ; Crashes = "; statSuiteObj.Crash;
? " Time spent: "; statSuiteObj.Time; "ms"
? "==="
m.printSuiteEnd(statSuiteObj.Name)
End Sub
'----------------------------------------------------------------
' Print test statistic.
'
' @param statTestObj (object) A target test object to print.
'----------------------------------------------------------------
Sub Logger__PrintTestStatistic(statTestObj as object)
m.printTestStart(statTestObj.Name)
? "--- Result: "; statTestObj.Result
? "--- Time: "; statTestObj.Time
if LCase(statTestObj.Result) <> "success"
? "--- Error Code: "; statTestObj.Error.Code
? "--- Error Message: "; statTestObj.Error.Message
end if
m.printTestEnd(statTestObj.Name)
End Sub
'----------------------------------------------------------------
' Print testting start message.
'----------------------------------------------------------------
Sub Logger__PrintStart()
? ""
? "******************************************************************"
? "******************************************************************"
? "************* Start testing *************"
? "******************************************************************"
End Sub
'----------------------------------------------------------------
' Print testing end message.
'----------------------------------------------------------------
Sub Logger__PrintEnd()
? "******************************************************************"
? "************* End testing *************"
? "******************************************************************"
? "******************************************************************"
? ""
End Sub
'----------------------------------------------------------------
' Print test suite start message.
'----------------------------------------------------------------
Sub Logger__PrintSuiteStart(sName as String)
? "================================================================="
? "=== Start "; sName; " suite:"
? "==="
End Sub
'----------------------------------------------------------------
' Print test suite end message.
'----------------------------------------------------------------
Sub Logger__PrintSuiteEnd(sName as String)
? "==="
? "=== End "; sName; " suite."
? "================================================================="
End Sub
'----------------------------------------------------------------
' Print test start message.
'----------------------------------------------------------------
Sub Logger__PrintTestStart(tName as String)
? "----------------------------------------------------------------"
? "--- Start "; tName; " test:"
? "---"
End Sub
'----------------------------------------------------------------
' Print test end message.
'----------------------------------------------------------------
Sub Logger__PrintTestEnd(tName as String)
? "---"
? "--- End "; tName; " test."
? "----------------------------------------------------------------"
End Sub