-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestSuiteRunner.ipf
executable file
·249 lines (207 loc) · 6.75 KB
/
TestSuiteRunner.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#pragma rtGlobals=1 // Use modern global access method.
// TestSuiteRunner -- a component of IgorUnit
// This data type is used to run the tests contained in a TestSuite
#ifndef IGORUNIT_TSR
#define IGORUNIT_TSR
#include "TestSuite"
#include "TestResult"
Structure TestSuiteRunner
Variable test_run_count
Variable curr_group_idx
Variable curr_grouptest_idx
Variable curr_test_idx
Variable curr_test_status
STRUCT TestSuite test_suite
STRUCT TestResult test_result
EndStructure
Function TSR_persist(tsr, to_dfref)
STRUCT TestSuiteRunner &tsr
DFREF to_dfref
Variable/G to_dfref:test_run_count = tsr.test_run_count
Variable/G to_dfref:curr_group_idx = tsr.curr_group_idx
Variable/G to_dfref:curr_grouptest_idx = tsr.curr_grouptest_idx
Variable/G to_dfref:curr_test_idx = tsr.curr_test_idx
Variable/G to_dfref:curr_test_status = tsr.curr_test_status
NewDataFolder/O to_dfref:test_suite
NewDataFolder/O to_dfref:test_result
TS_persist(tsr.test_suite, to_dfref:test_suite)
TR_persist(tsr.test_result, to_dfref:test_result)
End
Function TSR_load(tsr, from_dfref)
STRUCT TestSuiteRunner &tsr
DFREF from_dfref
NVAR test_run_count = from_dfref:test_run_count
NVAR curr_group_idx = from_dfref:curr_group_idx
NVAR curr_grouptest_idx = from_dfref:curr_grouptest_idx
NVAR curr_test_idx = from_dfref:curr_test_idx
NVAR curr_test_status = from_dfref:curr_test_status
tsr.test_run_count = test_run_count
tsr.curr_group_idx = curr_group_idx
tsr.curr_grouptest_idx = curr_grouptest_idx
tsr.curr_test_idx = curr_test_idx
tsr.curr_test_status = curr_test_status
TS_load(tsr.test_suite, from_dfref:test_suite)
TR_load(tsr.test_result, from_dfref:test_result)
End
Function TSR_init(tsr, ts)
STRUCT TestSuiteRunner &tsr
STRUCT TestSuite &ts
tsr.test_run_count = 0
tsr.curr_group_idx = 0
tsr.curr_grouptest_idx = 0
tsr.curr_test_idx = 0
tsr.curr_test_status = TEST_UNKNOWN
tsr.test_suite = ts
STRUCT TestResult tr
TR_init(tr)
tsr.test_result = tr
End
Function TSR_runAllTests(tsr)
STRUCT TestSuiteRunner &tsr
TR_addTestSuiteStart(tsr.test_result, tsr.test_suite)
TSR_persist(tsr, IgorUnit_getCurrentTSR())
do
TSR_load(tsr, IgorUnit_getCurrentTSR())
if (TSR_isDone(tsr))
break
endif
TSR_runNextTest(tsr)
while(1)
TR_addTestSuiteEnd(tsr.test_result, tsr.test_suite)
return TR_isAllPassed(tsr.test_result)
End
Function TSR_runNextTest(tsr)
STRUCT TestSuiteRunner &tsr
STRUCT UnitTest test
String testname = TSR_getNextTest(tsr, test)
TSR_runTest(tsr, test)
End
Function protofunc()
End
Function TSR_runTest(tsr, test)
STRUCT TestSuiteRunner &tsr
STRUCT UnitTest &test
String setupname = getGroupSetupName(test.groupname)
String teardownname = getGroupTeardownName(test.groupname)
FUNCREF protofunc group_setup = $setupname
FUNCREF protofunc group_teardown = $teardownname
FUNCREF protofunc curr_test = $test.funcname
tsr.curr_test_status = TEST_UNKNOWN
Variable start_time, end_time
String msg = ""
TSR_createTestDataFolder(tsr, test.funcname)
TSR_persist(tsr, IgorUnit_getCurrentTSR())
UnitTest_persist(test, IgorUnit_getCurrentUnitTest())
TR_addTestStart(tsr.test_result, test)
start_time = stopMSTimer(-2)
try
group_setup()
curr_test()
group_teardown()
end_time = stopMSTimer(-2)
TSR_load(tsr, IgorUnit_getCurrentTSR())
catch
end_time = stopMSTimer(-2)
TSR_load(tsr, IgorUnit_getCurrentTSR())
if (V_AbortCode == ASSERTION_FAILURE)
// do not run other tests if assertion fails
// assertion results have already been recorded
tsr.curr_test_status = TEST_FAILURE
elseif (V_AbortCode == ASSERTION_IGNORETEST)
tsr.curr_test_status = TEST_IGNORE
elseif (V_AbortCode == ASSERTION_SUCCESS)
tsr.curr_test_status = TEST_SUCCESS
else
// handle all other aborts as test errors
tsr.curr_test_status = TEST_ERROR
Variable err = GetRTError(1)
msg = GetErrMessage(err)
endif
endtry
Variable duration = end_time - start_time
switch(tsr.curr_test_status)
case TEST_SUCCESS:
TR_addTestSuccess(tsr.test_result, test, duration, msg)
break
case TEST_FAILURE:
TR_addTestFailure(tsr.test_result, test, duration, msg)
break
case TEST_IGNORE:
TR_addTestIgnore(tsr.test_result, test, duration, msg)
break
case TEST_ERROR:
TR_addTestError(tsr.test_result, test, duration, msg)
break
default:
break
endswitch
tsr.test_run_count += 1
TSR_persist(tsr, IgorUnit_getCurrentTSR())
TSR_deleteTestDataFolder(tsr, test.funcname)
IgorUnit_clearCurrentUnitTest()
End
Function/S getGroupSetupName(groupname)
String groupname
return "setup_" + groupname
End
Function/S getGroupTeardownName(groupname)
String groupname
return "teardown_" + groupname
End
Function TSR_createTestDataFolder(tsr, name)
STRUCT TestSuiteRunner &tsr
String name
String foldername = "Test_" + name
NewDataFolder/O/S root:$foldername
End
Function TSR_deleteTestDataFolder(tsr, name)
STRUCT TestSuiteRunner &tsr
String name
String foldername = "Test_" + name
KillDataFolder root:$foldername
End
Function TSR_getRunTestCount(tsr)
STRUCT TestSuiteRunner &tsr
return tsr.test_run_count
End
Function TSR_getTestCount(tsr)
STRUCT TestSuiteRunner &tsr
return TS_getTestCount(tsr.test_suite)
End
Function/S TSR_getNextTest(tsr, test)
STRUCT TestSuiteRunner &tsr
STRUCT UnitTest &test
if (TSR_isCurrentGroupDone(tsr))
TSR_getNextGroup(tsr)
endif
TS_getGroupTestByIndex(tsr.test_suite, tsr.curr_group_idx, tsr.curr_grouptest_idx, test)
tsr.curr_grouptest_idx += 1
tsr.curr_test_idx += 1
return test.testname
End
Function TSR_getCurrentGroup(tsr)
STRUCT TestSuiteRunner &tsr
return tsr.curr_group_idx
End
Function TSR_getNextGroup(tsr)
STRUCT TestSuiteRunner &tsr
tsr.curr_group_idx += 1
tsr.curr_grouptest_idx = 0
TR_addGroupStart(tsr.test_result, TS_getGroupNameByIndex(tsr.test_suite, tsr.curr_group_idx))
return TSR_getCurrentGroup(tsr)
End
Function TSR_isCurrentGroupDone(tsr)
STRUCT TestSuiteRunner &tsr
if (TS_getGroupTestCount(tsr.test_suite, tsr.curr_group_idx) == tsr.curr_grouptest_idx)
return TRUE
endif
return FALSE
End
Function TSR_isDone(tsr)
STRUCT TestSuiteRunner &tsr
if (tsr.curr_test_idx >= TSR_getTestCount(tsr))
return TRUE
endif
return FALSE
End
#endif