13
13
compliance with the License. You should have received a copy of the
14
14
Erlang Public License along with this software. If not, it can be
15
15
retrieved online at http://www.erlang.org/.
17
17
Software distributed under the License is distributed on an "AS IS"
18
18
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
19
the License for the specific language governing rights and limitations
24
24
<title>Event Handling</title>
64
<marker id="usage"></marker>
64
65
<title>Usage</title>
65
66
<p>Event handlers may be installed by means of an <c>event_handler</c>
66
start flag (<c>run_test</c>) or option (<c>ct:run_test/1</c>), where the
67
start flag (<c>ct_run</c>) or option (<c>ct:run_test/1</c>), where the
67
68
argument specifies the names of one or more event handler modules.
69
<p><c>$ run_test -suite test/my_SUITE -event_handler handlers/my_evh1
70
<p><c>$ ct_run -suite test/my_SUITE -event_handler handlers/my_evh1
70
71
handlers/my_evh2 -pa $PWD/handlers</c></p>
72
<p>Use the <c><![CDATA[ct_run -event_handler_init]]></c> option instead of
73
<c><![CDATA[-event_handler]]></c> to pass start arguments to the event handler
71
75
<p>All event handler modules must have gen_event behaviour. Note also that
72
76
these modules must be precompiled, and that their locations must be
73
77
added explicitly to the Erlang code server search path (like in the
76
<p>It is not possible to specify start arguments to the event handlers when
77
using the <c>run_test</c> script. You may however pass along start arguments
78
if you use the <c>ct:run_test/1</c> function. An event_handler tuple in the argument
79
<c>Opts</c> has the following definition (see also <c>ct:run_test/1</c> in the
80
reference manual):</p>
80
<p>An event_handler tuple in the argument <c>Opts</c> has the following
81
definition (see also <c>ct:run_test/1</c> in the reference manual):</p>
83
84
{event_handler,EventHandlers}
85
86
EventHandlers = EH | [EH]
86
87
EH = atom() | {atom(),InitArgs} | {[atom()],InitArgs}
88
InitArgs = [term()]</pre>
92
1> ct:run_test([{suite,"test/my_SUITE"},{event_handler,[my_evh1,{my_evh2,[node()]}]}]).
92
1> ct:run_test([{suite,"test/my_SUITE"},{event_handler,[my_evh1,{my_evh2,[node()]}]}]).</pre>
94
93
<p>This will install two event handlers for the <c>my_SUITE</c> test. Event handler
95
94
<c>my_evh1</c> is started with <c>[]</c> as argument to the init function. Event handler
96
95
<c>my_evh2</c> is started with the name of the current node in the init argument list.</p>
177
<marker id="tc_done"/>
177
178
<item><c>#event{name = tc_done, data = {Suite,FuncOrGroup,Result}}</c>
178
179
<p><c>Suite = atom()</c>, name of the suite.</p>
179
180
<p><c>FuncOrGroup = Func | {Conf,GroupName,GroupProperties}</c></p>
183
184
(unknown if init- or end function times out).</p>
184
185
<p><c>GroupProperties = list()</c>, list of execution properties for the group.</p>
185
186
<p><c>Result = ok | {skipped,SkipReason} | {failed,FailReason}</c>, the result.</p>
187
<marker id="skipreason"/>
186
188
<p><c>SkipReason = {require_failed,RequireInfo} |
187
189
{require_failed_in_suite0,RequireInfo} |
188
190
{failed,{Suite,init_per_testcase,FailInfo}} |
190
192
the reason why the case has been skipped.</p>
191
<p><c>FailReason = {error,FailInfo} |
193
<marker id="failreason"/>
194
<p><c>FailReason = {error,FailInfo} |
192
195
{error,{RunTimeError,StackTrace}} |
193
196
{timetrap_timeout,integer()} |
194
197
{failed,{Suite,end_per_testcase,FailInfo}}</c>, reason for failure.</p>
211
214
<c>end_per_testcase</c> for the case failed.
217
<marker id="tc_auto_skip"></marker>
214
218
<item><c>#event{name = tc_auto_skip, data = {Suite,Func,Reason}}</c>
215
219
<p><c>Suite = atom()</c>, the name of the suite.</p>
216
220
<p><c>Func = atom()</c>, the name of the test case or configuration function.</p>
236
240
skipped because of <c>init_per_testcase</c> failing, since that information is carried with
237
241
the <c>tc_done</c> event.
244
<marker id="tc_user_skip"></marker>
240
245
<item><c>#event{name = tc_user_skip, data = {Suite,TestCase,Comment}}</c>
241
246
<p><c>Suite = atom()</c>, name of the suite.</p>
242
247
<p><c>TestCase = atom()</c>, name of the test case.</p>