-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestListener_TestPrinter.ipf
executable file
·211 lines (163 loc) · 5.05 KB
/
TestListener_TestPrinter.ipf
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
#pragma rtGlobals=1 // Use modern global access method.
// TestPrinter TestListener -- a component of IgorUnit
// This interface responds to TestResult events by emitting output (printing!)
#ifndef IGORUNIT_TL_TESTPRINTER
#define IGORUNIT_TL_TESTPRINTER
#include "TestListener"
#include "OutputFormat"
Function TLTP_init(tl)
STRUCT TestListener &tl
TL_init(tl)
TL_setFuncPointers(tl, "TLTP")
End
Function/S TLTP_output(tl, out_string)
STRUCT TestListener &tl
String out_string
printf, "%s", out_string
End
Function/S TLTP_outputToString(tl, out_string)
STRUCT TestListener &tl
String out_string
tl.output += out_string
End
Function TLTP_addTestFailure(tl, tr, to)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT TestOutcome &to
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, OF_TestFailure(of, to))
End
Function TLTP_addTestSuccess(tl, tr, to)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT TestOutcome &to
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, OF_TestSuccess(of, to))
End
Function TLTP_addTestError(tl, tr, to)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT TestOutcome &to
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, OF_TestError(of, to))
End
Function TLTP_addTestIgnore(tl, tr, to)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT TestOutcome &to
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, OF_TestIgnore(of, to))
End
Function TLTP_addGroupStart(tl, tr, groupname)
STRUCT TestListener &tl
STRUCT TestResult &tr
String groupname
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, OF_GroupStart(of, groupname))
End
Function TLTP_addTestStart(tl, tr, test)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT UnitTest &test
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, OF_TestStart(of, test))
End
Function TLTP_addTestEnd(tl, tr, test)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT UnitTest &test
End
Function TLTP_addAssertFailure(tl, tr, test, assertion)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT UnitTest &test
STRUCT Assertion &assertion
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, OF_AssertFailure(of, test, assertion))
End
Function TLTP_addAssertSuccess(tl, tr, test, assertion)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT UnitTest &test
STRUCT Assertion &assertion
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, OF_AssertSuccess(of, test, assertion))
End
Function TLTP_addTestSuiteStart(tl, tr, ts)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT TestSuite &ts
End
Function TLTP_addTestSuiteEnd(tl, tr, ts)
STRUCT TestListener &tl
STRUCT TestResult &tr
STRUCT TestSuite &ts
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, "\r")
TL_output(tl, OF_TestSuiteSummary(of, tr, ts))
TL_output(tl, "\r")
TLTP_listFailures(tl, tr)
TL_output(tl, "\r")
TLTP_listErrors(tl, tr)
End
Function TLTP_listFailures(tl, tr)
STRUCT TestListener &tl
STRUCT TestResult &tr
Variable fail_count = TR_getFailureCount(tr)
if (fail_count == 0)
return 0
endif
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, formatSectionHeader("Test Failures"))
String fail_idxs = TR_getTestFailureIndices(tr)
STRUCT TestOutcome to
STRUCT Assertion assertion
Variable i, to_idx
for (i=0; i < fail_count; i+=1)
to_idx = str2num(List_getItem(fail_idxs, i))
TR_getTestOutcomeByIndex(tr, to_idx, to)
TL_output(tl, OF_TestOutcomeSummary(of, to))
String assert_idxs = TR_getAssertFailIndicesByTest(tr, to_idx)
Variable assert_count = List_getLength(assert_idxs)
if (assert_count > 0)
Variable j, a_idx
for (j=0; j < assert_count; j+=1)
a_idx = str2num(List_getItem(assert_idxs, j))
TR_getAssertByIndex(tr, a_idx, assertion)
TL_output(tl, OF_AssertionSummary(of, to, assertion))
endfor
endif
TL_output(tl, formatDefectFooter())
endfor
End
Function TLTP_listErrors(tl, tr)
STRUCT TestListener &tl
STRUCT TestResult &tr
Variable err_count = TR_getErrorCount(tr)
if (err_count == 0)
return 0
endif
STRUCT OutputFormat of
OutputFormat_factory(tl.verbosity, of)
TL_output(tl, formatSectionHeader("Test Errors"))
String err_idxs = TR_getTestErrorIndices(tr)
STRUCT TestOutcome to
Variable i, idx
for (i=0; i < err_count; i+=1)
idx = str2num(List_getItem(err_idxs, i))
TR_getTestOutcomeByIndex(tr, idx, to)
TL_output(tl, OF_TestOutcomeSummary(of, to))
TL_output(tl, formatDefectFooter())
endfor
End
#endif