xref: /minix3/external/bsd/bind/dist/unit/atf-src/atf-sh/atf-sh-api.3 (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1*00b67f09SDavid van Moolenbroek.\"	$NetBSD: atf-sh-api.3,v 1.3 2014/12/10 04:38:03 christos Exp $
2*00b67f09SDavid van Moolenbroek.\"
3*00b67f09SDavid van Moolenbroek.\"
4*00b67f09SDavid van Moolenbroek.\" Automated Testing Framework (atf)
5*00b67f09SDavid van Moolenbroek.\"
6*00b67f09SDavid van Moolenbroek.\" Copyright (c) 2008 The NetBSD Foundation, Inc.
7*00b67f09SDavid van Moolenbroek.\" All rights reserved.
8*00b67f09SDavid van Moolenbroek.\"
9*00b67f09SDavid van Moolenbroek.\" Redistribution and use in source and binary forms, with or without
10*00b67f09SDavid van Moolenbroek.\" modification, are permitted provided that the following conditions
11*00b67f09SDavid van Moolenbroek.\" are met:
12*00b67f09SDavid van Moolenbroek.\" 1. Redistributions of source code must retain the above copyright
13*00b67f09SDavid van Moolenbroek.\"    notice, this list of conditions and the following disclaimer.
14*00b67f09SDavid van Moolenbroek.\" 2. Redistributions in binary form must reproduce the above copyright
15*00b67f09SDavid van Moolenbroek.\"    notice, this list of conditions and the following disclaimer in the
16*00b67f09SDavid van Moolenbroek.\"    documentation and/or other materials provided with the distribution.
17*00b67f09SDavid van Moolenbroek.\"
18*00b67f09SDavid van Moolenbroek.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
19*00b67f09SDavid van Moolenbroek.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20*00b67f09SDavid van Moolenbroek.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21*00b67f09SDavid van Moolenbroek.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22*00b67f09SDavid van Moolenbroek.\" IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
23*00b67f09SDavid van Moolenbroek.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*00b67f09SDavid van Moolenbroek.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25*00b67f09SDavid van Moolenbroek.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*00b67f09SDavid van Moolenbroek.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27*00b67f09SDavid van Moolenbroek.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28*00b67f09SDavid van Moolenbroek.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29*00b67f09SDavid van Moolenbroek.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*00b67f09SDavid van Moolenbroek.\"
31*00b67f09SDavid van Moolenbroek.Dd June 28, 2010
32*00b67f09SDavid van Moolenbroek.Dt ATF-SH-API 3
33*00b67f09SDavid van Moolenbroek.Os
34*00b67f09SDavid van Moolenbroek.Sh NAME
35*00b67f09SDavid van Moolenbroek.Nm atf_add_test_case ,
36*00b67f09SDavid van Moolenbroek.Nm atf_check ,
37*00b67f09SDavid van Moolenbroek.Nm atf_check_equal ,
38*00b67f09SDavid van Moolenbroek.Nm atf_config_get ,
39*00b67f09SDavid van Moolenbroek.Nm atf_config_has ,
40*00b67f09SDavid van Moolenbroek.Nm atf_expect_death ,
41*00b67f09SDavid van Moolenbroek.Nm atf_expect_exit ,
42*00b67f09SDavid van Moolenbroek.Nm atf_expect_fail ,
43*00b67f09SDavid van Moolenbroek.Nm atf_expect_pass ,
44*00b67f09SDavid van Moolenbroek.Nm atf_expect_signal ,
45*00b67f09SDavid van Moolenbroek.Nm atf_expect_timeout ,
46*00b67f09SDavid van Moolenbroek.Nm atf_fail ,
47*00b67f09SDavid van Moolenbroek.Nm atf_get ,
48*00b67f09SDavid van Moolenbroek.Nm atf_get_srcdir ,
49*00b67f09SDavid van Moolenbroek.Nm atf_pass ,
50*00b67f09SDavid van Moolenbroek.Nm atf_require_prog ,
51*00b67f09SDavid van Moolenbroek.Nm atf_set ,
52*00b67f09SDavid van Moolenbroek.Nm atf_skip ,
53*00b67f09SDavid van Moolenbroek.Nm atf_test_case
54*00b67f09SDavid van Moolenbroek.Nd POSIX shell API to write ATF-based test programs
55*00b67f09SDavid van Moolenbroek.Sh SYNOPSIS
56*00b67f09SDavid van Moolenbroek.Fn atf_add_test_case "name"
57*00b67f09SDavid van Moolenbroek.Fn atf_check "command"
58*00b67f09SDavid van Moolenbroek.Fn atf_check_equal "expr1" "expr2"
59*00b67f09SDavid van Moolenbroek.Fn atf_config_get "var_name"
60*00b67f09SDavid van Moolenbroek.Fn atf_config_has "var_name"
61*00b67f09SDavid van Moolenbroek.Fn atf_expect_death "reason" "..."
62*00b67f09SDavid van Moolenbroek.Fn atf_expect_exit "exitcode" "reason" "..."
63*00b67f09SDavid van Moolenbroek.Fn atf_expect_fail "reason" "..."
64*00b67f09SDavid van Moolenbroek.Fn atf_expect_pass
65*00b67f09SDavid van Moolenbroek.Fn atf_expect_signal "signo" "reason" "..."
66*00b67f09SDavid van Moolenbroek.Fn atf_expect_timeout "reason" "..."
67*00b67f09SDavid van Moolenbroek.Fn atf_fail "reason"
68*00b67f09SDavid van Moolenbroek.Fn atf_get "var_name"
69*00b67f09SDavid van Moolenbroek.Fn atf_get_srcdir
70*00b67f09SDavid van Moolenbroek.Fn atf_pass
71*00b67f09SDavid van Moolenbroek.Fn atf_require_prog "prog_name"
72*00b67f09SDavid van Moolenbroek.Fn atf_set "var_name" "value"
73*00b67f09SDavid van Moolenbroek.Fn atf_skip "reason"
74*00b67f09SDavid van Moolenbroek.Fn atf_test_case "name" "cleanup"
75*00b67f09SDavid van Moolenbroek.Sh DESCRIPTION
76*00b67f09SDavid van MoolenbroekATF
77*00b67f09SDavid van Moolenbroekprovides a simple but powerful interface to easily write test programs in
78*00b67f09SDavid van Moolenbroekthe POSIX shell language.
79*00b67f09SDavid van MoolenbroekThese are extremely helpful given that they are trivial to write due to the
80*00b67f09SDavid van Moolenbroeklanguage simplicity and the great deal of available external tools, so they
81*00b67f09SDavid van Moolenbroekare often ideal to test other applications at the user level.
82*00b67f09SDavid van Moolenbroek.Pp
83*00b67f09SDavid van MoolenbroekTest programs written using this library must be run using the
84*00b67f09SDavid van Moolenbroek.Xr atf-sh 1
85*00b67f09SDavid van Moolenbroekinterpreter by putting the following on their very first line:
86*00b67f09SDavid van Moolenbroek.Bd -literal -offset indent
87*00b67f09SDavid van Moolenbroek#! /usr/bin/env atf-sh
88*00b67f09SDavid van Moolenbroek.Ed
89*00b67f09SDavid van Moolenbroek.Pp
90*00b67f09SDavid van MoolenbroekShell-based test programs always follow this template:
91*00b67f09SDavid van Moolenbroek.Bd -literal -offset indent
92*00b67f09SDavid van Moolenbroekatf_test_case tc1
93*00b67f09SDavid van Moolenbroektc1_head() {
94*00b67f09SDavid van Moolenbroek    ... first test case's header ...
95*00b67f09SDavid van Moolenbroek}
96*00b67f09SDavid van Moolenbroektc1_body() {
97*00b67f09SDavid van Moolenbroek    ... first test case's body ...
98*00b67f09SDavid van Moolenbroek}
99*00b67f09SDavid van Moolenbroek
100*00b67f09SDavid van Moolenbroekatf_test_case tc2 cleanup
101*00b67f09SDavid van Moolenbroektc2_head() {
102*00b67f09SDavid van Moolenbroek    ... second test case's header ...
103*00b67f09SDavid van Moolenbroek}
104*00b67f09SDavid van Moolenbroektc2_body() {
105*00b67f09SDavid van Moolenbroek    ... second test case's body ...
106*00b67f09SDavid van Moolenbroek}
107*00b67f09SDavid van Moolenbroektc2_cleanup() {
108*00b67f09SDavid van Moolenbroek    ... second test case's cleanup ...
109*00b67f09SDavid van Moolenbroek}
110*00b67f09SDavid van Moolenbroek
111*00b67f09SDavid van Moolenbroek.Ns ... additional test cases ...
112*00b67f09SDavid van Moolenbroek
113*00b67f09SDavid van Moolenbroekatf_init_test_cases() {
114*00b67f09SDavid van Moolenbroek    atf_add_test_case tc1
115*00b67f09SDavid van Moolenbroek    atf_add_test_case tc2
116*00b67f09SDavid van Moolenbroek    ... add additional test cases ...
117*00b67f09SDavid van Moolenbroek}
118*00b67f09SDavid van Moolenbroek.Ed
119*00b67f09SDavid van Moolenbroek.Ss Definition of test cases
120*00b67f09SDavid van MoolenbroekTest cases have an identifier and are composed of three different parts:
121*00b67f09SDavid van Moolenbroekthe header, the body and an optional cleanup routine, all of which are
122*00b67f09SDavid van Moolenbroekdescribed in
123*00b67f09SDavid van Moolenbroek.Xr atf-test-case 4 .
124*00b67f09SDavid van MoolenbroekTo define test cases, one can use the
125*00b67f09SDavid van Moolenbroek.Fn atf_test_case
126*00b67f09SDavid van Moolenbroekfunction, which takes a first parameter specifiying the test case's
127*00b67f09SDavid van Moolenbroekname and instructs the library to set things up to accept it as a valid
128*00b67f09SDavid van Moolenbroektest case.
129*00b67f09SDavid van MoolenbroekThe second parameter is optional and, if provided, must be
130*00b67f09SDavid van Moolenbroek.Sq cleanup ;
131*00b67f09SDavid van Moolenbroekproviding this parameter allows defining a cleanup routine for the test
132*00b67f09SDavid van Moolenbroekcase.
133*00b67f09SDavid van MoolenbroekIt is important to note that this function
134*00b67f09SDavid van Moolenbroek.Em does not
135*00b67f09SDavid van Moolenbroekset the test case up for execution when the program is run.
136*00b67f09SDavid van MoolenbroekIn order to do so, a later registration is needed through the
137*00b67f09SDavid van Moolenbroek.Fn atf_add_test_case
138*00b67f09SDavid van Moolenbroekfunction detailed in
139*00b67f09SDavid van Moolenbroek.Sx Program initialization .
140*00b67f09SDavid van Moolenbroek.Pp
141*00b67f09SDavid van MoolenbroekLater on, one must define the three parts of the body by providing two
142*00b67f09SDavid van Moolenbroekor three functions (remember that the cleanup routine is optional).
143*00b67f09SDavid van MoolenbroekThese functions are named after the test case's identifier, and are
144*00b67f09SDavid van Moolenbroek.Fn <id>_head ,
145*00b67f09SDavid van Moolenbroek.Fn <id>_body
146*00b67f09SDavid van Moolenbroekand
147*00b67f09SDavid van Moolenbroek.Fn <id>_cleanup.
148*00b67f09SDavid van MoolenbroekNone of these take parameters when executed.
149*00b67f09SDavid van Moolenbroek.Ss Program initialization
150*00b67f09SDavid van MoolenbroekThe test program must define an
151*00b67f09SDavid van Moolenbroek.Fn atf_init_test_cases
152*00b67f09SDavid van Moolenbroekfunction, which is in charge of registering the test cases that will be
153*00b67f09SDavid van Moolenbroekexecuted at run time by using the
154*00b67f09SDavid van Moolenbroek.Fn atf_add_test_case
155*00b67f09SDavid van Moolenbroekfunction, which takes the name of a test case as its single parameter.
156*00b67f09SDavid van MoolenbroekThis main function should not do anything else, except maybe sourcing
157*00b67f09SDavid van Moolenbroekauxiliary source files that define extra variables and functions.
158*00b67f09SDavid van Moolenbroek.Ss Configuration variables
159*00b67f09SDavid van MoolenbroekThe test case has read-only access to the current configuration variables
160*00b67f09SDavid van Moolenbroekthrough the
161*00b67f09SDavid van Moolenbroek.Fn atf_config_has
162*00b67f09SDavid van Moolenbroekand
163*00b67f09SDavid van Moolenbroek.Fn atf_config_get
164*00b67f09SDavid van Moolenbroekmethods.
165*00b67f09SDavid van MoolenbroekThe former takes a single parameter specifying a variable name and returns
166*00b67f09SDavid van Moolenbroeka boolean indicating whether the variable is defined or not.
167*00b67f09SDavid van MoolenbroekThe latter can take one or two parameters.
168*00b67f09SDavid van MoolenbroekIf it takes only one, it specifies the variable from which to get the
169*00b67f09SDavid van Moolenbroekvalue, and this variable must be defined.
170*00b67f09SDavid van MoolenbroekIf it takes two, the second one specifies a default value to be returned
171*00b67f09SDavid van Moolenbroekif the variable is not available.
172*00b67f09SDavid van Moolenbroek.Ss Access to the source directory
173*00b67f09SDavid van MoolenbroekIt is possible to get the path to the test case's source directory from
174*00b67f09SDavid van Moolenbroekanywhere in the test program by using the
175*00b67f09SDavid van Moolenbroek.Fn atf_get_srcdir
176*00b67f09SDavid van Moolenbroekfunction.
177*00b67f09SDavid van MoolenbroekIt is interesting to note that this can be used inside
178*00b67f09SDavid van Moolenbroek.Fn atf_init_test_cases
179*00b67f09SDavid van Moolenbroekto silently include additional helper files from the source directory.
180*00b67f09SDavid van Moolenbroek.Ss Requiring programs
181*00b67f09SDavid van MoolenbroekAside from the
182*00b67f09SDavid van Moolenbroek.Va require.progs
183*00b67f09SDavid van Moolenbroekmeta-data variable available in the header only, one can also check for
184*00b67f09SDavid van Moolenbroekadditional programs in the test case's body by using the
185*00b67f09SDavid van Moolenbroek.Fn atf_require_prog
186*00b67f09SDavid van Moolenbroekfunction, which takes the base name or full path of a single binary.
187*00b67f09SDavid van MoolenbroekRelative paths are forbidden.
188*00b67f09SDavid van MoolenbroekIf it is not found, the test case will be automatically skipped.
189*00b67f09SDavid van Moolenbroek.Ss Test case finalization
190*00b67f09SDavid van MoolenbroekThe test case finalizes either when the body reaches its end, at which
191*00b67f09SDavid van Moolenbroekpoint the test is assumed to have
192*00b67f09SDavid van Moolenbroek.Em passed ,
193*00b67f09SDavid van Moolenbroekor at any explicit call to
194*00b67f09SDavid van Moolenbroek.Fn atf_pass ,
195*00b67f09SDavid van Moolenbroek.Fn atf_fail
196*00b67f09SDavid van Moolenbroekor
197*00b67f09SDavid van Moolenbroek.Fn atf_skip .
198*00b67f09SDavid van MoolenbroekThese three functions terminate the execution of the test case immediately.
199*00b67f09SDavid van MoolenbroekThe cleanup routine will be processed afterwards in a completely automated
200*00b67f09SDavid van Moolenbroekway, regardless of the test case's termination reason.
201*00b67f09SDavid van Moolenbroek.Pp
202*00b67f09SDavid van Moolenbroek.Fn atf_pass
203*00b67f09SDavid van Moolenbroekdoes not take any parameters.
204*00b67f09SDavid van Moolenbroek.Fn atf_fail
205*00b67f09SDavid van Moolenbroekand
206*00b67f09SDavid van Moolenbroek.Fn atf_skip
207*00b67f09SDavid van Moolenbroektake a single string parameter that describes why the test case failed or
208*00b67f09SDavid van Moolenbroekwas skipped, respectively.
209*00b67f09SDavid van MoolenbroekIt is very important to provide a clear error message in both cases so that
210*00b67f09SDavid van Moolenbroekthe user can quickly know why the test did not pass.
211*00b67f09SDavid van Moolenbroek.Ss Expectations
212*00b67f09SDavid van MoolenbroekEverything explained in the previous section changes when the test case
213*00b67f09SDavid van Moolenbroekexpectations are redefined by the programmer.
214*00b67f09SDavid van Moolenbroek.Pp
215*00b67f09SDavid van MoolenbroekEach test case has an internal state called
216*00b67f09SDavid van Moolenbroek.Sq expect
217*00b67f09SDavid van Moolenbroekthat describes what the test case expectations are at any point in time.
218*00b67f09SDavid van MoolenbroekThe value of this property can change during execution by any of:
219*00b67f09SDavid van Moolenbroek.Bl -tag -width indent
220*00b67f09SDavid van Moolenbroek.It Fn atf_expect_death "reason" "..."
221*00b67f09SDavid van MoolenbroekExpects the test case to exit prematurely regardless of the nature of the
222*00b67f09SDavid van Moolenbroekexit.
223*00b67f09SDavid van Moolenbroek.It Fn atf_expect_exit "exitcode" "reason" "..."
224*00b67f09SDavid van MoolenbroekExpects the test case to exit cleanly.
225*00b67f09SDavid van MoolenbroekIf
226*00b67f09SDavid van Moolenbroek.Va exitcode
227*00b67f09SDavid van Moolenbroekis not
228*00b67f09SDavid van Moolenbroek.Sq -1 ,
229*00b67f09SDavid van Moolenbroek.Xr atf-run 1
230*00b67f09SDavid van Moolenbroekwill validate that the exit code of the test case matches the one provided
231*00b67f09SDavid van Moolenbroekin this call.
232*00b67f09SDavid van MoolenbroekOtherwise, the exact value will be ignored.
233*00b67f09SDavid van Moolenbroek.It Fn atf_expect_fail "reason"
234*00b67f09SDavid van MoolenbroekAny failure raised in this mode is recorded, but such failures do not report
235*00b67f09SDavid van Moolenbroekthe test case as failed; instead, the test case finalizes cleanly and is
236*00b67f09SDavid van Moolenbroekreported as
237*00b67f09SDavid van Moolenbroek.Sq expected failure ;
238*00b67f09SDavid van Moolenbroekthis report includes the provided
239*00b67f09SDavid van Moolenbroek.Fa reason
240*00b67f09SDavid van Moolenbroekas part of it.
241*00b67f09SDavid van MoolenbroekIf no error is raised while running in this mode, then the test case is
242*00b67f09SDavid van Moolenbroekreported as
243*00b67f09SDavid van Moolenbroek.Sq failed .
244*00b67f09SDavid van Moolenbroek.Pp
245*00b67f09SDavid van MoolenbroekThis mode is useful to reproduce actual known bugs in tests.
246*00b67f09SDavid van MoolenbroekWhenever the developer fixes the bug later on, the test case will start
247*00b67f09SDavid van Moolenbroekreporting a failure, signaling the developer that the test case must be
248*00b67f09SDavid van Moolenbroekadjusted to the new conditions.
249*00b67f09SDavid van MoolenbroekIn this situation, it is useful, for example, to set
250*00b67f09SDavid van Moolenbroek.Fa reason
251*00b67f09SDavid van Moolenbroekas the bug number for tracking purposes.
252*00b67f09SDavid van Moolenbroek.It Fn atf_expect_pass
253*00b67f09SDavid van MoolenbroekThis is the normal mode of execution.
254*00b67f09SDavid van MoolenbroekIn this mode, any failure is reported as such to the user and the test case
255*00b67f09SDavid van Moolenbroekis marked as
256*00b67f09SDavid van Moolenbroek.Sq failed .
257*00b67f09SDavid van Moolenbroek.It Fn atf_expect_signal "signo" "reason" "..."
258*00b67f09SDavid van MoolenbroekExpects the test case to terminate due to the reception of a signal.
259*00b67f09SDavid van MoolenbroekIf
260*00b67f09SDavid van Moolenbroek.Va signo
261*00b67f09SDavid van Moolenbroekis not
262*00b67f09SDavid van Moolenbroek.Sq -1 ,
263*00b67f09SDavid van Moolenbroek.Xr atf-run 1
264*00b67f09SDavid van Moolenbroekwill validate that the signal that terminated the test case matches the one
265*00b67f09SDavid van Moolenbroekprovided in this call.
266*00b67f09SDavid van MoolenbroekOtherwise, the exact value will be ignored.
267*00b67f09SDavid van Moolenbroek.It Fn atf_expect_timeout "reason" "..."
268*00b67f09SDavid van MoolenbroekExpects the test case to execute for longer than its timeout.
269*00b67f09SDavid van Moolenbroek.El
270*00b67f09SDavid van Moolenbroek.Ss Helper functions for common checks
271*00b67f09SDavid van Moolenbroek.Fn atf_check [options] command [args]
272*00b67f09SDavid van Moolenbroek.Pp
273*00b67f09SDavid van MoolenbroekThis function wraps the execution of the
274*00b67f09SDavid van Moolenbroek.Nm atf-check
275*00b67f09SDavid van Moolenbroektool and makes the test case fail if the tool reports failure.
276*00b67f09SDavid van MoolenbroekYou should always use this function instead of the tool in your scripts.
277*00b67f09SDavid van MoolenbroekFor more details on the parameters of this function, refer to
278*00b67f09SDavid van Moolenbroek.Xr atf-check 1 .
279*00b67f09SDavid van Moolenbroek.Pp
280*00b67f09SDavid van Moolenbroek.Fn atf_check_equal expr1 expr2
281*00b67f09SDavid van Moolenbroek.Pp
282*00b67f09SDavid van MoolenbroekThis function takes two expressions, evaluates them and, if their
283*00b67f09SDavid van Moolenbroekresults differ, aborts the test case with an appropriate failure message.
284*00b67f09SDavid van Moolenbroek.Sh EXAMPLES
285*00b67f09SDavid van MoolenbroekThe following shows a complete test program with a single test case that
286*00b67f09SDavid van Moolenbroekvalidates the addition operator:
287*00b67f09SDavid van Moolenbroek.Bd -literal -offset indent
288*00b67f09SDavid van Moolenbroekatf_test_case addition
289*00b67f09SDavid van Moolenbroekaddition_head() {
290*00b67f09SDavid van Moolenbroek    atf_set "descr" "Sample tests for the addition operator"
291*00b67f09SDavid van Moolenbroek}
292*00b67f09SDavid van Moolenbroekaddition_body() {
293*00b67f09SDavid van Moolenbroek    atf_check_equal $((0 + 0)) 0
294*00b67f09SDavid van Moolenbroek    atf_check_equal $((0 + 1)) 1
295*00b67f09SDavid van Moolenbroek    atf_check_equal $((1 + 0)) 0
296*00b67f09SDavid van Moolenbroek
297*00b67f09SDavid van Moolenbroek    atf_check_equal $((1 + 1)) 2
298*00b67f09SDavid van Moolenbroek
299*00b67f09SDavid van Moolenbroek    atf_check_equal $((100 + 200)) 300
300*00b67f09SDavid van Moolenbroek}
301*00b67f09SDavid van Moolenbroek
302*00b67f09SDavid van Moolenbroekatf_init_test_cases() {
303*00b67f09SDavid van Moolenbroek    atf_add_test_case addition
304*00b67f09SDavid van Moolenbroek}
305*00b67f09SDavid van Moolenbroek.Ed
306*00b67f09SDavid van Moolenbroek.Pp
307*00b67f09SDavid van MoolenbroekThis other example shows how to include a file with extra helper functions
308*00b67f09SDavid van Moolenbroekin the test program:
309*00b67f09SDavid van Moolenbroek.Bd -literal -offset indent
310*00b67f09SDavid van Moolenbroek.Ns ... definition of test cases ...
311*00b67f09SDavid van Moolenbroek
312*00b67f09SDavid van Moolenbroekatf_init_test_cases() {
313*00b67f09SDavid van Moolenbroek    . $(atf_get_srcdir)/helper_functions.sh
314*00b67f09SDavid van Moolenbroek
315*00b67f09SDavid van Moolenbroek    atf_add_test_case foo1
316*00b67f09SDavid van Moolenbroek    atf_add_test_case foo2
317*00b67f09SDavid van Moolenbroek}
318*00b67f09SDavid van Moolenbroek.Ed
319*00b67f09SDavid van Moolenbroek.Pp
320*00b67f09SDavid van MoolenbroekThis example demonstrates the use of the very useful
321*00b67f09SDavid van Moolenbroek.Fn atf_check
322*00b67f09SDavid van Moolenbroekfunction:
323*00b67f09SDavid van Moolenbroek.Bd -literal -offset indent
324*00b67f09SDavid van Moolenbroek# Check for silent output
325*00b67f09SDavid van Moolenbroekatf_check 'true' 0 null null
326*00b67f09SDavid van Moolenbroek
327*00b67f09SDavid van Moolenbroek# Check for silent output and failure
328*00b67f09SDavid van Moolenbroekatf_check 'false' 1 null null
329*00b67f09SDavid van Moolenbroek
330*00b67f09SDavid van Moolenbroek# Check for known stdout and silent stderr
331*00b67f09SDavid van Moolenbroekecho foo >expout
332*00b67f09SDavid van Moolenbroekatf_check 'echo foo' 0 expout null
333*00b67f09SDavid van Moolenbroek
334*00b67f09SDavid van Moolenbroek# Generate a file for later inspection
335*00b67f09SDavid van Moolenbroekatf_check 'ls' 0 stdout null
336*00b67f09SDavid van Moolenbroekgrep foo ls || atf_fail "foo file not found in listing"
337*00b67f09SDavid van Moolenbroek.Ed
338*00b67f09SDavid van Moolenbroek.Sh SEE ALSO
339*00b67f09SDavid van Moolenbroek.Xr atf-sh 1 ,
340*00b67f09SDavid van Moolenbroek.Xr atf-test-program 1 ,
341*00b67f09SDavid van Moolenbroek.Xr atf-test-case 4 ,
342*00b67f09SDavid van Moolenbroek.Xr atf 7
343